UVA 10608 Friends
来源:互联网 发布:读书郎软件下载 编辑:程序博客网 时间:2024/04/30 02:26
Description
There is a town with N citizens. It is known that some pairs of people are friends. According to the famous saying that “The friends of my friends are my friends, too” it follows that if A and B are friends and B and C are friends then A and C are friends, too.
Your task is to count how many people there are in the largest group of friends.
Input
Input consists of several datasets. The first line of the input consists of a line with the number of test cases to follow. The first line of each dataset contains tho numbers N and M, where N is the number of town's citizens (1≤N≤30000) and M is the number of pairs of people (0≤M≤500000), which are known to be friends. Each of the following M lines consists of two integers A and B (1≤A≤N, 1≤B≤N, A≠B) which describe that A and B are friends. There could be repetitions among the given pairs.
Output
The output for each test case should contain one number denoting how many people there are in the largest group of friends.
Sample Input
Sample Output
2
3 2
1 2
2 3
10 12
1 2
3 1
3 4
5 4
3 5
4 6
5 2
2 1
7 10
1 2
9 10
8 9
3
6
#include <iostream>#include <cstring>#define maxn 30005using namespace std;int f[maxn],ans[maxn];int find(int x){ if(f[x]==x) return x; else return(f[x]=find(f[x])); }int main(){ int N;cin>>N; while(N--) { int n,m;cin>>n>>m;int i;for(i=1;i<=n;i++)f[i]=i;memset(ans,0,sizeof(ans));for(i=1;i<=m;i++){int x,y;cin>>x>>y;int fx,fy;fx=find(x);fy=find(y);if(fx!=fy)f[fx]=fy;}for(i=1;i<=n;i++)ans[find(i)]++;int max=0;for(i=1;i<=n;i++)if(ans[i]>max)max=ans[i];cout<<max<<endl; } return 0;}
代码还没有ac,无论是在UVA上还是虚拟oj上都显示,In judge queue
表示很无语,等了好长时间,虚拟oj显示 Judging Error 2。淡淡的忧桑。。
更新:已经ac
- UVa 10608 - Friends
- UVa 10608 - Friends
- Uva 10608 - Friends
- UVa 10608 Friends
- UVa:10608 Friends
- UVA - 10608 Friends
- UVA 10608 Friends
- UVa 10608 - Friends
- UVA 10608 Friends
- UVA 10608 Friends
- UVA - 10608 Friends
- Uva 10608 Friends
- uva 10608Friends
- uva 10608 - Friends(并查集)
- uva 10608 - Friends (并查集)
- UVA 10608 - Friends (并查集)
- UVa 10608 - Friends(并查集)
- UVA - 10608-Friends(并查集)
- SVG与JS的交互
- struts2文件上传
- robotium的截图代码
- Maven常用命令
- SQL Server 锁的排队机制
- UVA 10608 Friends
- (4)Android入门——android四大组件基础介绍及打电话,发短信简单应用 &单元测试
- ubuntu 14.04 下安装sublime text 2
- 关于环境变量的配置技巧
- 在Linux下搭建ssl vpn,构建企业安全内网
- robotium自动化测试应主意点
- 连载:面向对象葵花宝典:思想、技巧与实践(38) - 设计模式之道
- DP优化——四边形不等式(简介)
- java中的char