int n,m,a[6d6],b[6d6],k; ll cost[501][501],c[6d6],dist[5d5]; int to_i(int x,int y,int f){return (y*n+x)*2+f;} { rd(n,m); rep(i,m){ ll@h,@w,@c; cost[h-1][w-1]=c; } VI d{1,0,-1,0,1}; rep(i,n)rep(j,n)rep(_,4){ int y=i+d[_],x=j+d[_+1]; if(0<=xg; g.setDirectEdge(5d5,k,a,b,c); g.getDist(0,dist); wt(dist[to_i(n-1,n-1,1)]); }