#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e3+5, mod = 1e9+7;
int a[N], n, m;
int d[N];
bool vis[N];
struct node {
	int y, w;
	bool operator < (const node a) const {
		return w > a.w;
	}
};
vector<node> g[N];
int num[N]; // 最短路数量 
int f[N]; // 消防队员的数量 
int pre[N]; // 记录到到这个点的前第一个位置 
void dijkstra(int s) {
	memset(d, 0x3f, sizeof d);
	priority_queue<node> q;
	d[s] = 0;
	q.push({s, 0});
	num[s] = 1;
	f[s] = a[s];
	while(!q.empty()) {
		node t = q.top();
		int x = t.y;
		q.pop();
		if(vis[x]) continue;
		vis[x] = true;

		for(int i = 0; i < g[x].size(); i++) {
			int y = g[x][i].y, w = g[x][i].w;
			if(vis[y]) continue;
			if(d[y] > d[x] + w) {
				d[y] = d[x] + w;
				num[y] = num[x]; 
				q.push({y, d[y]});
				f[y] = f[x] + a[y]; 
				pre[y] = x; 
			} 
			else if(d[y] == d[x] + w){
				num[y] += num[x];
				if(f[y] < f[x] + a[y]){
					f[y] = f[x] + a[y];
					pre[y] = x;
				}
			}
		}
	}
}

signed main() {
	int s, t;
	cin >> n >> m >> s >> t;
	s++, t++;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++){
		int x, y, w;
		cin >> x >> y >> w;
		x++, y++;
		g[x].push_back({y, w});
		g[y].push_back({x, w});
	}
	dijkstra(s);
	cout << num[t] << " " << f[t] << "\n"; 
	stack<int> ans;
	while(t){
		ans.push(t);
		t = pre[t];
	}
	while(!ans.empty())	{
		cout << ans.top() - 1 << ' ';
		ans.pop();
	}
	return 0;
}


1 条评论

  • 1