并查集 5-30 tree ------错误方法
来源:互联网 发布:中国网络发展的评价 编辑:程序博客网 时间:2024/05/16 05:39
#include <iostream>
using namespace std;
int fa[100000];// father
int f_u(int x)
{
int root=x;
while(fa[root]!=root) root=fa[root];
while(fa[x]!=x)
{
int y=fa[x];
fa[x]=root;
x=y;
}
return root;
}
int main()
{
int n,m;
cin>>n>>m;
int x,y;
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
int fx=f_u(x);
int fy=f_u(y);
if(fx!=fy) fa[fx]=fy;
}
for(int i=1;i<=n;i++) f_u(i); //不知道为什么要多找一次
for(int i=1;i<=n;i++)
cout<<"i="<<i<<" fa="<<fa[i]<<endl;
return 0;
}
2 0
- 并查集 5-30 tree ------错误方法
- 5-30 并查集 tree
- Tree(并查集)
- hdu5606 tree 并查集
- hdu5606 Tree (并查集)
- 【并查集】Is it a tree?
- 【并查集】Is it A Tree?
- 并查集,贪心:Color A Tree
- 【并查集】 HDOJ 4786 Fibonacci Tree
- Is It A Tree?(并查集)
- HDU 5200 Tree (离线并查集)
- hdu 4786 Fibonacci Tree(并查集)
- hdoj tree 5606 (并查集)
- hdoj 5606 tree 【并查集】
- HDOJ 5606 tree(并查集)
- 【并查集】HDOJ tree 5606
- HDU 5606 tree(并查集)
- hdoj--5606--tree(并查集)
- 5.16cxb排序题目
- 5-16 冒泡排序
- Tree(2015nhoi第三题)
- n种钱几种分法程序
- 2015年南海区初中信息学竞赛试题解题报告
- 并查集 5-30 tree ------错误方法
- 7.27~7.28总结(不包括题目总结)
- 5-30 并查集 tree
- 2015 NOIP考后心得
- 6-6 并查集练习——friend
- stone二分答案
- 为什么Int类型的取值范围是2的31次方减1
- 6-6 并查集练习——ttime
- message