#include #include #include #include using namespace std; using i64 = long long; struct edge { int to, cost; }; int n, m; vector> prev2; vector on_path; void rec(int i) { if(i == 0) { on_path[i] = true; return; } if(on_path[i]) { return; } on_path[i] = true; for(int j : prev2[i]) { rec(j); } } int main(void) { scanf("%d%d", &n, &m); vector> G(n, vector()); // G[n][] for(int i=0; i cost(n, 0); // cost[n] prev2.assign(n, vector()); queue> que; // コスト、点番号 que.emplace(0, 0); while(!que.empty()) { int _, v; tie(_, v) = que.front(); que.pop(); for(edge e : G[v]) { if(cost[e.to] < cost[v] + e.cost) { cost[e.to] = cost[v] + e.cost; que.emplace(cost[e.to], e.to); prev2[e.to].clear(); prev2[e.to].push_back(v); } else if(cost[e.to] == cost[v] + e.cost) { prev2[e.to].push_back(v); } } } int res = cost[n-1]; on_path.assign(n, false); rec(n-1); int cnt = 0; for(int i=0; i