Describe
http://www.lydsy.com/JudgeOnline/problem.php?id=1001
Analysis
The minimum cut of plane plan is converted into dual graph to find the shortest way, classic.
Attention:
1. The priority queue is a large heap.
2.Dijkstra can take a vis array, or without, because after a point comes out, its updated point and the original point in the queue is larger than it, so it could not be updated to a smaller, after this point out of the team when the situation is not better than the first time, so the team will not have operations.
3. Two-way side, the array to open enough (seemingly not the first time to make this error).
4. Online people say m==1| | N==1 can not be a special case, in the GET function can be handled properly, man.
#include <cstdio>#include<queue>#include<algorithm>using namespacestd;Const intmaxn= ++Ten, oo=1<< -;intn,m,cnt;intd[maxn*maxn*2],head[maxn*maxn*4];BOOLvis[maxn*maxn*2];structedge{intTo,w,next; Edge () {} Edge (intAintBintc): to (a), W (b), Next (c) {}BOOL operator< (ConstEdge &a)Const{returna.w<W;}} G[MAXN*maxn*6];voidInsertint from,intTo,intW) {g[++cnt]=edge (to,w,head[ from]); head[ from]=CNT; g[++cnt]=edge ( from, W,head[to]); head[to]=CNT;} int Get(intXintYintz) { if(x<1|| Y>=M)return((n1) * (M-1) <<1)+1; if(x>=n| | y<1)return 0; return(((X1) * (M-1) +y-1) <<1) +z+1;}intDijkstra (intSintt) { for(intI=0; i<= (n1) * (M-1) <<1)+1; i++) d[i]=Oo; D[s]=0; Priority_queue<edge>Q; Q.push (Edge (s),0,0)); while(!Q.empty ()) {Edge e=q.top (); Q.pop (); intx=e.to; if(Vis[x])Continue; VIS[X]=true; for(intI=head[x];i;i=G[i].next) { inty=g[i].to; if(d[y]>d[x]+G[I].W) {D[y]=d[x]+G[I].W; Q.push (Edge (y,d[y),0)); } } } returnd[t];} voidinit () { for(intI=1; i<=n;i++){ for(intj=1; j<m;j++){ intA scanf"%d",&a); Insert (Get(I,j,1),Get(I-1J0), a); } } for(intI=1; i<n;i++){ for(intj=1; j<=m;j++){ intA scanf"%d",&a); Insert (Get(i,j-1,1),Get(I,j,0), a); } } for(intI=1; i<n;i++){ for(intj=1; j<m;j++){ intA scanf"%d",&a); Insert (Get(I,j,0),Get(I,j,1), a); } }} intMain () {scanf ("%d%d",&n,&m); Init (); printf ("%d\n", Dijkstra (0, ((n1) * (M-1) <<1)+1)); return 0;}
View Code
Bzoj_1001_ Wolf Catch Rabbit (plan for minimum cut + dual graph to find the shortest path)