原题链接
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, s, d;
int c[N];
int p[N], road[N], cnt[N];
int dist[N];
bool st[N];
int h[N], e[N], ne[N], w[N], idx;
typedef pair<int, int> PII;
void add(int a, int b, int c)
{
e[idx] = b;
w[idx] = c;
ne[idx] = h[a];
h[a] = idx++;
}
void Dijkstra()
{
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
priority_queue<PII, vector<PII>, greater<PII>> heap;
dist[s] = 0;
heap.push({0, s});
cnt[s] = c[s];
road[s] = 1;
while (heap.size())
{
auto t = heap.top();
heap.pop();
int now = t.second;
if (st[now])
continue;
st[now] = true;
if(now == d)
break;
for (int i = h[now]; i != -1; i = ne[i])
{
int to = e[i];
int val = w[i];
if (dist[to] > dist[now] + val)
{
dist[to] = dist[now] + val;
cnt[to] = cnt[now] + c[to];
road[to] = road[now];
p[to] = now;
heap.push({dist[to], to});
}
else if (dist[to] == dist[now] + val)
{
road[to] += road[now];
if (cnt[to] < cnt[now] + c[to])
{
cnt[to] = cnt[now] + c[to];
p[to] = now;
}
}
}
}
}
int main()
{
memset(h, -1, sizeof h);
memset(p, -1, sizeof p);
scanf("%d%d%d%d", &n, &m, &s, &d);
for (int i = 0; i < n; i++)
{
scanf("%d", &c[i]);
}
while (m--)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
add(a, b, c);
add(b, a, c);
}
Dijkstra();
cout << road[d] << ' ' << cnt[d] << endl;
stack<int> stk;
int now = d;
while (now != -1)
{
stk.push(now);
now = p[stk.top()];
}
while (stk.size())
{
cout << stk.top();
if (stk.size() != 1)
cout << ' ';
stk.pop();
}
return 0;
}