bzoj1116: [POI2008]CLO
生活随笔
收集整理的這篇文章主要介紹了
bzoj1116: [POI2008]CLO
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳送門:http://www.lydsy.com/JudgeOnline/problem.php?id=1116
題目大意:Byteotia城市有n個 towns m條雙向roads. 每條 road 連接 兩個不同的 towns ,沒有重復的road. 你要把其中一些road變成單向邊使得:每個town都有且只有一個入度
題解:并查集
代碼:
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdio> 5 #include<cmath> 6 #define maxn 100005 7 using namespace std; 8 int n,m; 9 int fa[maxn]; 10 bool mark[maxn]; 11 int read() 12 { 13 int x=0; char ch; bool bo=0; 14 while (ch=getchar(),ch<'0'||ch>'9') if (ch=='-') bo=1; 15 while (x=x*10+ch-'0',ch=getchar(),ch>='0'&&ch<='9') ; 16 if (bo) return -x; return x; 17 } 18 int find(int x) 19 { 20 if (fa[x]!=x) fa[x]=find(fa[x]); 21 return fa[x]; 22 } 23 int main() 24 { 25 n=read(); m=read(); 26 for (int i=1; i<=n; i++) fa[i]=i; 27 for (int i=1; i<=m; i++) 28 { 29 int u=read(),v=read(); 30 int q=find(u),p=find(v); 31 if (q!=p) 32 { 33 fa[q]=p; mark[p]=mark[p] | mark[q]; 34 } 35 else 36 mark[q]=1; 37 } 38 for (int i=1; i<=n; i++) 39 if (!mark[find(i)]) 40 { 41 printf("NIE"); 42 return 0; 43 } 44 printf("TAK"); return 0; 45 } View Code?
轉載于:https://www.cnblogs.com/HQHQ/p/5578220.html
總結
以上是生活随笔為你收集整理的bzoj1116: [POI2008]CLO的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 脱壳_详细_使用的方法_01
- 下一篇: 6/12 Sprint2 看板和燃尽图