#include #include #include #include using namespace std; using i64 = long long; struct edge { int to, cost; }; int n, m; int main(void) { scanf("%d%d", &n, &m); vector> G0(n, vector()); // G[n][] vector> rG(n, vector()); // revG[n][] for(int i=0; i cost0(n, 0); // cost[n] queue> que0; // コスト、点番号 que0.emplace(0, 0); while(!que0.empty()) { int _, v; tie(_, v) = que0.front(); que0.pop(); for(edge e : G0[v]) { if(cost0[e.to] < cost0[v] + e.cost) { cost0[e.to] = cost0[v] + e.cost; que0.emplace(cost0[e.to], e.to); } } } vector rcost(n, 0); // rcost[n] queue> rq; // コスト、点番号 rq.emplace(0, n-1); while(!rq.empty()) { int _, v; tie(_, v) = rq.front(); rq.pop(); for(edge e : rG[v]) { if(rcost[e.to] < rcost[v] + e.cost) { rcost[e.to] = rcost[v] + e.cost; rq.emplace(rcost[e.to], e.to); } } } for(int i=0; i