UVa 10985 Rings ' n ' Ropes floyd+bfs

Source: Internet
Author: User
Tags cas

n rings and a rope with a length of 1 m

Ask the right hand to hold any 2 rings up to a few ropes straightened

Hold which 2 don't know so 22 enum

For 2 rings You can consider the shortest possible short circuit and then there may be a number of the shortest lines in the path statistics.

I know how to get out of a sample.

Example 3 is a ring pull 0 and 2 you have 2 of the shortest, each one is 3.

Example 4 is the same

#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std;
const int MAX = 130;
int A[max][max];
int Map[max][max];
BOOL Vis[max][max];
int n,m;
int cnt;
	void Floyd () {int i,j,k; for (k = 0, k < n; k++) for (i = 0, i < n; i++) for (j = 0; J < N; j + +) A[i][j] = min (a[i][j],a[i][k]+a[k][
J]);
	} void BFs (int s,int e) {queue <int> q;
	Q.push (s);
	int i;
		while (!q.empty ()) {int u = q.front ();
		Q.pop ();
			for (i = 0; i < n; i++) {if (vis[u][i]) continue;
			if (!map[u][i]) continue;
				if (A[e][i] + 1 = = A[e][u]) {cnt++;
				Vis[u][i] = Vis[i][u] = true;
			Q.push (i);
	}}}} int main () {int t,cas = 1;
	int i,j;
	int s,e;
	scanf ("%d", &t);
		while (t--) {memset (a,0,sizeof (a));
		memset (map,0,sizeof (map));
		scanf ("%d%d", &n,&m);
				for (i = 0; i < n; i++) for (j = 0; J < N; j + +) {if (i = = j) A[i][j] = 0;
		else a[i][j] = 999999999;	} for (i = 0; i < m; i++) {scanf ("%d%d", &s,&e);
			A[s][e] = A[e][s] = 1;
		Map[s][e] = Map[e][s] = 1;
		} Floyd ();
		int max = 0;
				
				for (i = 0, i < n; i++) {for (j = i+1; J < N; j + +) {if (a[i][j] = = 999999999) continue;
				memset (vis,false,sizeof (VIS));
				CNT = 0;
				BFS (I,J);
			if (Max < CNT) max = CNT;
		}}//printf ("%d%d\n", a[0][1],a[1][0]);
	printf ("Case #%d:%d\n", Cas++,max);
} 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.