Extension and application of POJ 1388 Hinge Node problem Floyd algorithm

Source: Internet
Author: User
POJ 1388
//sep9
#include <iostream>
using namespace std;
const int maxn=128;
Char S[MAXN][MAXN];
int G[MAXN][MAXN];
int HINGE[MAXN][MAXN];
int VIS[MAXN];
int main ()
{
	int n;
	while (scanf ("%d", &n) ==1&&n) {
		memset (hinge,0,sizeof (hinge));
		for (int i=1;i<=n;++i)
			scanf ("%s", S[i]);
		for (int. i=1;i<=n;++i) for
			(int j=1;j<=n;++j)
				g[i][j]=s[i][j-1]-' 0 ';
		for (int k=1;k<=n;++k) for (int
			i=1;i<=n;++i) for
				(int j=1;j<=n;++j)
					if (g[i][k]&&g[k ][j]) {
						if (g[i][j]==0| | G[I][K]+G[K][J]<G[I][J])
							hinge[i][j]=k,g[i][j]=g[i][k]+g[k][j];
						else if (G[i][k]+g[k][j]==g[i][j])
							hinge[i][j]=0;
					}					
		memset (vis,0,sizeof (Vis));
		for (int i=1;i<=n;++i) for
			(int j=i+1;j<=n;++j)
				vis[hinge[i][j]]=1;
		int ans=0;
		for (int i=1;i<=n;++i)
			ans+=vis[i];
		printf ("%d\n", ans);
	}
	return 0;	
}

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.