#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=0; j> G(n, vector()); // G[n][] for(int i=0; i cost(n, 0); // cost[n] prev2.assign(n, vector(n, false)); 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); for(int i=0; i