bzoj1116: [POI2008]CLO
2016-06-12 17:19
369 查看
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1116
题目大意:Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个town都有且只有一个入度
题解:并查集
代码:
View Code
题目大意:Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个town都有且只有一个入度
题解:并查集
代码:
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> #define maxn 100005 using namespace std; int n,m; int fa[maxn]; bool mark[maxn]; int read() { int x=0; char ch; bool bo=0; while (ch=getchar(),ch<'0'||ch>'9') if (ch=='-') bo=1; while (x=x*10+ch-'0',ch=getchar(),ch>='0'&&ch<='9') ; if (bo) return -x; return x; } int find(int x) { if (fa[x]!=x) fa[x]=find(fa[x]); return fa[x]; } int main() { n=read(); m=read(); for (int i=1; i<=n; i++) fa[i]=i; for (int i=1; i<=m; i++) { int u=read(),v=read(); int q=find(u),p=find(v); if (q!=p) { fa[q]=p; mark[p]=mark[p] | mark[q]; } else mark[q]=1; } for (int i=1; i<=n; i++) if (!mark[find(i)]) { printf("NIE"); return 0; } printf("TAK"); return 0; }
View Code
相关文章推荐
- 生成英语单词
- Linux用户磁盘配额
- RequireJS入门(二)
- CPU卡相关资料收集总结
- Android学习笔记——界面相关逻辑
- Android 编程下 Touch 事件的分发和消费机制
- Shell命令速查
- 上下移动jquery
- Android通用流行框架大全
- Linux磁盘分区实战案例
- poj 2723
- Libcurl笔记三
- 不同版本PHP之间cURL的区别
- java基础整理-File类
- 单点登录SSO的实现原理
- Linux中文显示设置
- python学习笔记 可变参数关键字参数**kw相关学习
- Appium总结
- bzoj1529: [POI2005]ska Piggy banks
- C#编写ActiveX网页截图控件