[RW] [SSL2344 maximum communication block]

Description

Some campers is a city, in fact, they only need a can, because people do in the future to get a CD-ROM, other people can hold things like U disk to copy ah!

But after DYJ survey found that some campers are not so cooperative, they are willing to come to him a copy of some information, of course, may be reluctant to allow others to come to him a copy of the information, which is alien to the spirit of cooperation and team!

Now assume campers total of N (2 <= N <= 200), the number of each camper is 1 ~ N. DJY to each person issued a questionnaire, so that each camper who fill their willingness to make a copy of the information to come to him. Of course, if A is willing to copy data to B, and B and willing to copy the data to C, then A was provided with information once, then B, C will obtain information.

Now you write a program, according to recover up questionnaire to help DZY calculate at least organizing committee how many discs you want to burn in order to ensure that all campers can go back and get information summer camp?

The meaning of problems

This question can know careful appreciated: in fact, there are several requirements of the communication block in FIG.

Input

First, a number N, followed by N lines, respectively, each of the campers are willing to get their own copy of the information to which other campers. That is, the input data of the N + 1 represent the i-th row campers willing to copy data to those campers number to a zero terminated. If campers do not want a copy of the information to any person, the corresponding row is only one zero, a number between the number of row separated by a space.

Output

A positive integer representing the minimum number of CD you want to burn.

Sample Input

5
2 4 3 0
4 5 0
0
0
1 0

Sample Output

1

analysis

This problem is FLOYED Dafa. Adjacency matrix with pre-existing well and then determines whether floyed communication, and then to count the number.

The Code

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,ans,f[201],x,a[201][201];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		while(cin>>x&&x!=0)//输入 
		a[i][x]=1;  //标为连通
	} 
	for(int k=1;k<=n;k++)
	   for(int i=1;i<=n;i++)
	      for(int j=1;j<=n;j++)
         	a[i][j]=a[i][j]||(a[i][k]&&a[k][j]);  //Floyed判断是否连通
	for(int i=1;i<=n;i++) 
	{
		f[i]=i;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[i][j])/*访问过*/ f[j]=f[i];
		} 
	}
	for(int i=1;i<=n;i++)
	{
		if(f[i]==i) ans++;  //统计
	} 
	cout<<ans;
	return 0;
}


Published 63 original articles · won praise 61 · views 5482

Guess you like

Origin blog.csdn.net/dglyr/article/details/104016936