HDU 4370 0 or 1 min. ring

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.