【rqnoj】PID343 mty的考验
2016-06-19 21:30
344 查看
题解
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int father[1000+10];
int a[1000+10];
void init(int n)
{
for(int i=1;i<=n;i++)
father[i]=i;
}
int find(int x)
{
if(x!=father[x]) father[x]=find(father[x]);
return father[x];
}
void Union(int x,int y)
{
x=find(x);
y=find(y);
father[y]=x;
}
int main()
{
int ans=0;
int n,m,x,y;
cin>>n>>m;
init(n);
for(int i=1;i<=m;i++)
{
cin>>x>>y;
Union(x,y);
}
for(int i=1;i<=n;i++)
{
a[find(i)]++;
ans=max(a[find(i)],ans);
}
cout<<ans;
return 0;
}
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int father[1000+10];
int a[1000+10];
void init(int n)
{
for(int i=1;i<=n;i++)
father[i]=i;
}
int find(int x)
{
if(x!=father[x]) father[x]=find(father[x]);
return father[x];
}
void Union(int x,int y)
{
x=find(x);
y=find(y);
father[y]=x;
}
int main()
{
int ans=0;
int n,m,x,y;
cin>>n>>m;
init(n);
for(int i=1;i<=m;i++)
{
cin>>x>>y;
Union(x,y);
}
for(int i=1;i<=n;i++)
{
a[find(i)]++;
ans=max(a[find(i)],ans);
}
cout<<ans;
return 0;
}
相关文章推荐
- 1611:The Suspects
- 作业四,1001
- 作业四1002
- 作业四1003
- 练习四1005
- HDU-1213-How Many Tables
- Longest Consecutive Sequence,Distinct Subsequences,Interleaving String,Scramble String
- [NOIP2003]逻辑推理
- 并查集_POJ 1182_食物链
- SARS病毒传染 并查集
- HDU 1213
- CSU1307 并查集+SPFA
- 并查集
- BestWiring——Kruskal算法&并查集
- 1611:The Suspects
- 并查集示例1
- 并查集(union-find)学习报告
- poj3728
- HDU-1233 还是畅通工程(最小生成树&并查集)
- Simon-【深入理解数据结构】有根树的不同实现① —— 并查集