#include <bits/stdc++.h>
The topic requires 01 of the Matrix
The first line, except A11, can only have 1 1
The last column except Ann can only have 1 1
In addition to the four edges of the matrix, the points inside require that the number of rows 1 of the point be equal
Finally we can find that if the topic gives a complete graph of the Benquan matrix, then the 01 matrix shows a path on this graph
Cleverly modified SPFA to find the smallest ring on OK
using namespacestd;#defineLL Long LongConst intmaxn=3e2+Ten;intDIS[MAXN];BOOLVIS[MAXN];intA[MAXN][MAXN];intN;intSPFA (intSt) {Queue<int>Q; memset (DIS,0x3f,sizeofdis); for(intI=1; i<=n;i++) { if(i==st)Continue; Q.push (i); Vis[i]=true; Dis[i]=A[st][i]; } while(!Q.empty ()) { intU=q.front (); Q.pop (); vis[u]=0; for(intv=1; v<=n;v++) { if(V==u)Continue; if(dis[v]>dis[u]+A[u][v]) {Dis[v]=dis[u]+A[u][v]; if(!Vis[v]) Q.push (v), Vis[v]=1; } } }//for (int i=1;i<=n;i++)//printf ("%d", Dis[i]);p rintf ("\ n"); return 0;}intMain () {#ifdef Shuaishuai freopen ("In.txt","R", stdin); #endif //Shuaishuai while(~SCANF ("%d",&N)) { for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) scanf ("%d",&A[i][j]); intS,b,c; SPFA (1); S=dis[1]; C=Dis[n]; SPFA (n); b=Dis[n]; printf ("%d\n", Min (c,s+b)); } return 0;}
HDU 4370 0 or 1 min. ring