BZOJ 1116 [POI2008]CLO 并查集
来源:互联网 发布:山西东华软件 编辑:程序博客网 时间:2024/06/06 07:41
题意:链接
方法:并查集
解析:
第一眼神题,看完hz题解后发现被D了。
明明sb题。
如果某个连通块里存在环那么一定会达到目标状态。
为什么?
自己YY:)
所以并查集合并就行了。
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 100100using namespace std;int n,m;int fa[N];int v[N];int find(int x){ if(fa[x]==x)return x; return fa[x]=find(fa[x]);}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)fa[i]=i; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); int fx=find(x),fy=find(y); if(fx!=fy) { fa[fx]=fy; v[fy]=(v[fy]==1||v[fx]==1); }else { v[fx]=1; } } for(int i=1;i<=n;i++) { if(!v[find(i)]) { puts("NIE"); return 0; } } puts("TAK");}
0 0
- 【并查集】【bzoj 1116】: [POI2008]CLO
- BZOJ 1116 POI2008 CLO 并查集
- BZOJ 1116 [POI2008]CLO 并查集
- BZOJ 1116: [POI2008]CLO 并查集
- BZOJ 1116: [POI2008]CLO 并查集
- POI2008 BZOJ 1116 CLO -并查集-基环树
- 1116: [POI2008]CLO (并查集)
- 1116: [POI2008]CLO 思路题 并查集
- BZOJ1116: [POI2008]CLO 并查集
- 【BZOJ 1116】 [POI2008]CLO
- BZOJ 1116: [POI2008]CLO
- BZOJ 1116: [POI2008]CLO BZOJ
- BZOJ1116 CLO [并查集]
- 1116: [POI2008]CLO|深度搜索
- POI2008 CLO
- CLO [POI/BZOJ 1116]
- 【BZOJ】【P1116】【POI2008】【CLO】【题解】【生成树+dfs】
- bzoj1116 [POI2008]CLO
- NSAttributedString
- C++中的异常处理
- [Unity3D]Unity3D游戏开发之从Unity3D到Eclipse
- 黑马程序员---Java基础---面向对象:类的组成部分
- 解决centos7命令行中文乱码
- BZOJ 1116 [POI2008]CLO 并查集
- JavaScript 事件
- Leftmost Digit
- unicode码的分布情况
- [Unity3D]Unity3D游戏开发之在Android视图中嵌入Unity视图
- Oracle学习笔记20150915常见循环语句以及goto语句
- TCP协议三次握手
- 浮躁的过去,开启的项目管理之路(一)
- SQL占用CPU100%