int u[1d5],v[1d5]; ll c[1d5],d[1d5]; map,ll> costmap; { int @n,@m; rd((u,v,c,d)(m)); rep(i,m){ costmap[{u[i],v[i]}]=c[i]|d[i]<<32; costmap[{v[i],u[i]}]=c[i]|d[i]<<32; } graph g; g.setEdge(n+1,m,u,v); ll sum=0; DijkstraHeap h; h.walloc(n+1); rep(2){ h.init(n+1); h.change(1,0); while(h.size){ int i=h.pop(); rep[g.edge[i]](j,g.es[i]){ long co=costmap[{i,j}]; h.change(j,h.val[i]+(int)co); } } sum+=h.val[n]; int i=n; do{ rep(k,g.es[i]){ int j=g.edge[i][k]; long co=costmap[{i,j}]; if(h.val[i]==h.val[j]+(int)co){ co>>=32; costmap[{i,j}]=co|co<<32; costmap[{j,i}]=co|co<<32; i=j; break; } } }while(i!=1); } wt(sum); }