#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a>> cg; vector>> dg; const ll INF=1e18; map,int> mp; ll dijkstra(vector &path){ priority_queue,vector>,greater>> PQ; PQ.push(mkp(0,0)); vector dist(N,INF); vector prev(N,-1); dist[0]=0; while(!PQ.empty()){ auto f=PQ.top(); PQ.pop(); int now=f.second; ll d=f.first; if(dist[now]dist[now]+cost){ prev[to]=now; dist[to]=dist[now]+cost; PQ.push(mkp(dist[to],to)); } } for(auto e:dg[now]){ int to=e.first; ll cost=e.second; if(mp.count(minmax(now,to))==false) continue; if(dist[to]>dist[now]+cost){ prev[to]=now; dist[to]=dist[now]+cost; PQ.push(mkp(dist[to],to)); } } } int now=N-1; while(prev[now]!=-1){ path.push_back(now); now=prev[now]; } path.push_back(now); reverse(all(path)); return dist[N-1]; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>N>>M; cg.resize(N); dg.resize(N); rep(i,M){ int a,b,c,d; cin>>a>>b>>c>>d; a--;b--; cg[a].push_back(mkp(b,c)); cg[b].push_back(mkp(a,c)); dg[a].push_back(mkp(b,d)); dg[b].push_back(mkp(a,d)); } vector onepath; ll ares=dijkstra(onepath); for(int i=0;i+1 twopath; ll bres=dijkstra(twopath); cout<