#include using namespace std; long long mod = 998244353; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector>> Graph(N),rev(N); for(int i=0; i> u >> v; u--; v--; long long t; cin >> t; Graph.at(u).push_back({v,t}); rev.at(v).push_back({u,t}); } vector already(N); vector dist1(N,2e18); priority_queue,vector>,greater>> Q; Q.push({0,N-1}); dist1.at(N-1) = 0; while(Q.size()){ auto[pdist,pos] = Q.top(); Q.pop(); if(already.at(pos)) continue; already.at(pos) = true; for(auto [to,cost] : Graph.at(pos)){ if(dist1.at(to) > pdist+cost){ dist1.at(to) = pdist+cost; Q.push({dist1.at(to),to}); } } } already.assign(N,false); vector dist2(N,2e18); Q.push({0,N-2}); dist2.at(N-2) = 0; while(Q.size()){ auto[pdist,pos] = Q.top(); Q.pop(); if(already.at(pos)) continue; already.at(pos) = true; for(auto [to,cost] : Graph.at(pos)){ if(dist2.at(to) > pdist+cost){ dist2.at(to) = pdist+cost; Q.push({dist2.at(to),to}); } } } already.assign(N,false); vector dist3(N,2e18); Q.push({0,N-1}); dist3.at(N-1) = 0; while(Q.size()){ auto[pdist,pos] = Q.top(); Q.pop(); if(already.at(pos)) continue; already.at(pos) = true; for(auto [to,cost] : rev.at(pos)){ if(dist3.at(to) > pdist+cost){ dist3.at(to) = pdist+cost; Q.push({dist3.at(to),to}); } } } already.assign(N,false); vector dist4(N,2e18); Q.push({0,N-2}); dist4.at(N-2) = 0; while(Q.size()){ auto[pdist,pos] = Q.top(); Q.pop(); if(already.at(pos)) continue; already.at(pos) = true; for(auto [to,cost] : rev.at(pos)){ if(dist4.at(to) > pdist+cost){ dist4.at(to) = pdist+cost; Q.push({dist4.at(to),to}); } } } for(int i=0; i