#include using namespace std; using ll=long long; using Pair=pair; const ll INF=1e18; void dijkstra(ll s,vector> &G,vector &dist){ priority_queue,greater> que; que.push({0,s}); while(!que.empty()){ ll to=que.top().second,cost=que.top().first; if(cost> N >> M; vector> G1(N),G2(M); for(int i=0;i> u >> v >> t; u--,v--; G1[u].push_back({v,t}); G2[v].push_back({u,t}); } vector dist1(N,INF),dist2(N,INF),dist3(N,INF),dist4(N,INF); dijkstra(N-2,G1,dist1); dijkstra(N-2,G2,dist2); dijkstra(N-1,G1,dist3); dijkstra(N-1,G2,dist4); for(int i=0;i