#include <bits/stdc++.h>
using namespace std;
struct Edg {
int idx, fair;
Edg(int i, int f) : idx(i), fair(f) {}
bool operator<(const Edg& a) const { return a.fair < fair; }
};
int N, M, From, To, dist[1001], trace[1001];
vector<Edg> v[1001];
int main()
{
memset(dist, 0x3f, sizeof dist);
scanf("%d %d", &N, &M);
for (int i = 0, f, t, w; i < M; ++i) {
scanf("%d %d %d", &f, &t, &w);
v[f].push_back({ t, w });
}
scanf("%d %d", &From, &To);
dist[From] = 0;
priority_queue<Edg> pq;
pq.push({ From, 0 });
while (!pq.empty()) {
auto now = pq.top();
pq.pop();
if (now.fair != dist[now.idx]) continue;
for (auto& nxt : v[now.idx]) {
if (dist[nxt.idx] > nxt.fair + now.fair) {
dist[nxt.idx] = nxt.fair + now.fair;
trace[nxt.idx] = now.idx;
pq.push({ nxt.idx, dist[nxt.idx] });
}
}
}
vector<int> ans;
int tmp = To;
while (tmp) {
ans.push_back(tmp);
tmp = trace[tmp];
}
printf("%d\n%d\n", dist[To], ans.size());
for (int i = (int)ans.size() - 1; i >= 0; --i)
printf("%d ", ans[i]);
return 0;
}
댓글