#include #include #include #include using namespace std; using i64 = long long; struct edge { int to, cost; }; int main(void) { int n, m; scanf("%d%d", &n, &m); vector> G0(n, vector()); // G[n][] vector> rG(n, vector()); // revG[n][] for(int i=0; i cost0(n, -1); // cost[n] cost0[0] = 0; priority_queue, vector>> que0; // コスト、点番号 que0.emplace(0, 0); while(!que0.empty()) { int c, v; tie(c, v) = que0.top(); que0.pop(); if(c > cost0[v]) { continue; } 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, -1); // rcost[n] rcost[n-1] = 0; priority_queue, vector>> rq; // コスト、点番号 rq.emplace(0, n-1); while(!rq.empty()) { int c, v; tie(c, v) = rq.top(); rq.pop(); if(c > rcost[v]) { continue; } 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); } } } int days = cost0[n-1]; int cnt = 0; for(int i=0; i