#include using namespace std; typedef unsigned int uint; typedef long long int ll; typedef unsigned long long int ull; #define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout< ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<>=1,k++)s=(s<<1)|(u&1);for(;0>=1)cout<<(s&1);}} #define TIME chrono::system_clock::now() #define MILLISEC(t) (chrono::duration_cast(t).count()) template ostream& operator <<(ostream &o,const pair p){o<<"("<> vertex[100010]; vector> vertex_rev[100010]; int dp[100010]; int dp2[100010]; int main(){ int i,j,k; int x,y,a,b; cin>>n>>m; for (i=0;i> pq; pq.push(vector{0,0}); int from,to,tick,cost,num; while (!pq.empty()){ const vector& vref=pq.top(); tick = -vref[0]; from = vref[1]; pq.pop(); if (tick < dp[from]) continue; for (auto p_to : vertex[from]){ to = p_to.first; cost = p_to.second; if (dp[to] < tick + cost){ dp[to] = tick + cost; pq.push(vector{-dp[to],to}); } } } pq.push(vector{dp[n-1],n-1}); dp2[n-1] = dp[n-1]; while (!pq.empty()){ const vector& vref=pq.top(); tick = vref[0]; from = vref[1]; pq.pop(); if (tick > dp2[from]){continue;} for (auto p_to : vertex_rev[from]){ to = p_to.first; cost = p_to.second; if (!dp2[to]|| dp2[to]>tick-cost){ dp2[to] = tick-cost; pq.push(vector{dp2[to],to}); } } } int work=0; for (i=0;i