6-6 并查集练习——ttime
来源:互联网 发布:电子手轮 单片机 编辑:程序博客网 时间:2024/06/05 06:07
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("ttime.in");
ofstream fout("ttime.out");
#define cin fin
#define cout fout
int fa[100001];
int u_f(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,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
int fx=u_f(x);
int fy=u_f(y);
if(fx!=fy)
fa[fy]=fx;
}
int x[q+1],y[q+1];
for(int i=0;i<q;i++)
cin>>x[i]>>y[i];
for(int i=0;i<q;i++)
if(u_f(x[i]) != u_f(y[i]))
cout<<"N\n";
else cout<<"Y\n";
return 0;
}
- 6-6 并查集练习——ttime
- 6-6 并查集练习——friend
- 并查集练习
- 今天再练习并查集——hdu 1213
- 并查集练习---poj 1417 并查集+DP
- 图结构练习——最小生成树--使用并查集算法
- 树结构练习——判断给定森林中有多少棵树-并查集
- 并查集专题练习(一)POJ1611
- 并查集练习---poj 1182 食物链
- 并查集练习---poj 1984
- 并查集练习---poj 2912
- 并查集及 编程练习
- 并查集入门水题练习
- Friend解题报告 - 并查集练习
- 编程练习四(并查集)
- 【带权并查集】 练习
- 并查集练习1:HDOJ1213
- 并查集练习2:HDOJ1232
- 5-30 并查集 tree
- 2015 NOIP考后心得
- 6-6 并查集练习——friend
- stone二分答案
- 为什么Int类型的取值范围是2的31次方减1
- 6-6 并查集练习——ttime
- message
- tree 用点、边的算法
- 最大差值----美团2016研发工程师在线编程题
- Salesman 总结
- galaxy 原来的方法——超时(没有压缩路径)
- LCA
- 6-17 创新班第十课
- 离散事件模拟-银行管理