Vegetable and Road [并查集]
来源:互联网 发布:多线程socket编程java 编辑:程序博客网 时间:2024/06/06 20:02
公园终于建好了,市政府要求任意两个公园之间必须连通,即公园A到公园B至少有一条马路(并不是要求直接相连,可以通过其他公园间接相连)。
Vegetable接下来这个任务,并设计出了对应的修路方案,下面你需要判断Vegetable的方案是否可行。
注意:两个公园直接可以存在多条路。
输入
有T组测试数据,每组测试数据有一组N(0
#include<cstdio>#include<cstring>#include<cmath>#include<stack>#include<queue>#include<algorithm>using namespace std;#define INF 0x3f3f3f3f#define ll long longint par[1005];bool vl[1005];int n;void init(){ for (int i = 1; i <= n; ++i){ par[i] = i; }}int find(int x){ int temp = x; if (x == par[x]) return x; return par[x] = find(par[x]);}void unit(int x,int y){ vl[x] = true; vl[y] = true; int tx = find(x); int ty = find(y); if (tx == ty) return ; par[ty] = tx; }int u,v;int main(){ int t; scanf("%d",&t); while (t--){ memset(vl,false,sizeof(vl)); int m; scanf("%d%d",&n,&m); init(); int ta; for (int i= 0; i < m; ++i){ scanf("%d%d",&u,&v); unit(u,v); } int flag = 1; for (int i = 1; i <= n; ++i){ for (int j = 1; j <= n; ++j){ if (find(i)!=find(j)) flag = 0; } } if (flag == 0) printf("No\n"); else printf("Yes\n"); } return 0;}
wa了好几次在判断是否有森林上
这个题每个公园的坐标为1到n直接搜1到n
需要好好的整理一下并查集的知识点了
模板题都能卡= =
0 0
- Vegetable and Road [并查集]
- 问题 G: Vegetable and Road【并查集】
- 1284: Vegetable and Road
- HPU 1284: Vegetable and Road
- 1285: Vegetable and Road again
- HPU 1285: Vegetable and Road again
- Vegetable and Road again [最小生成树]
- 问题 H: Vegetable and Road again【最小生成树】
- 1285: Vegetable and Road again [最小生成树]
- [NOIP模拟] Road (并查集)
- Vegetable and Park [搜索]
- 1283: Vegetable and Park
- Vegetable and Park
- hdu1598 find the most comfortable road 并查集
- hdoj 1598 find the most comfortable road(并查集)
- 【并查集】find the most comfortable road
- 【hdu】 find the most comfortable road (并查集)
- find the most comfortable road(并查集)
- Qtudp组播编程
- 【题解】codeforces778C Peterson Polyglot
- 八大排序算法 java
- 热修复比较
- GraphX pregel接口
- Vegetable and Road [并查集]
- HDOJ题目分类
- opencv,图像处理,rgb转换为hsv空间
- 浅谈C/C++中运算符的优先级、运算符的结合性以及操作数的求值顺序
- 2017年3月4号。
- Dijistra求最短路(邻接表存储,前向星存储,堆优化)
- poj 1860 Bellman算法
- FastCGI和php-fpm的区别
- EasyClient实现IPCamera摄像机远程云台控制、语音对讲等功能