并查集 POJ 1330
来源:互联网 发布:苏宁易购和淘宝哪个好 编辑:程序博客网 时间:2024/06/06 02:14
#include <iostream>#include<stdio.h>#include<string.h>using namespace std;const int maxn = 10010;int t,n;int x,y;int father[maxn],bj[maxn];void bl(int n){ while(n !=father[n]) { bj[n] = 1; n = father[n]; } bj[n] = 1; return;}int sh(int m){ while(bj[m] != 1) { m = father[m]; } return m;}int main(){ scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) { father[i] = i; } for(int i=1;i<=n-1;i++) { int a,b; scanf("%d%d",&a,&b); father[b] = a; } memset(bj,0,sizeof(bj)); scanf("%d%d",&x,&y); bl(x); int ans = sh(y); printf("%d\n",ans); } return 0;}
0 0
- 并查集 POJ 1330
- Poj 并查集
- poj并查集
- POJ 并查集
- POJ 1330(LCA tarjan 并查集)
- poj 2524 并查集
- POJ 2236 并查集
- 并查集 POJ 2524
- 并查集 POJ 1611
- POJ 1182 并查集
- POJ 1703 并查集
- POJ 2492 并查集
- poj-1308 并查集
- poj-1703 并查集
- poj-2524 并查集
- 【并查集】POJ-1611
- POJ - 2492 并查集
- poj 1703 并查集
- 推荐一篇tarjan的神解释
- 2016/8/27
- Ajax与Json
- SHELL脚本语句 if、for、while、case 图示
- ubuntu16.04 开发软件 装机设置
- 并查集 POJ 1330
- Scanner和BufferReader用法详记
- 让Spark如虎添翼的Zeppelin – 分享篇
- C++对字符串流的读写
- linux软件包管理--RPM包 【二进制包】
- RGB模型转换到hsv原理及其opencv实现代码
- java7,8中的String pool
- Spark 运行模式 standalong & yarn
- Java内存分配及垃圾回收