#include #include #include using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x> G(n, vector()); for(int i : range(m)) { int a, b, c; scanf("%d%d%d", &a, &b, &c); G[a].push_back(edge(b, c)); G[b].push_back(edge(a, c)); } vector cost(n, inf); cost[g] = 0; priority_queue, vector>, greater>> que; // first: コスト, second: 点番号 que.push(make_pair(0, g)); while(!que.empty()) { pair cur = que.top(); que.pop(); int v = cur.second; for(int i : range(G[v].size())) { edge e = G[v][i]; if(cost[e.to] > cost[v] + e.cost) { cost[e.to] = cost[v] + e.cost; que.push(make_pair(cost[e.to], e.to)); } } } int v = s; vector res; res.push_back(v); while(v != g) { int next = inf; for(int i : range(G[v].size())) { edge e = G[v][i]; if(cost[v] == cost[e.to] + e.cost) { next = min(next, e.to); } } v = next; res.push_back(v); } for(int i : range(res.size())) { if(i!=0) { putchar(' '); } printf("%d", res[i]); } puts(""); return 0; }