# BZOJ1116: [POI2008]CLO

## 1116: [POI2008]CLO

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 565  Solved: 303
[Submit][Status]

## Output

TAK或者NIE 常做POI的同学,应该知道这两个单词的了...

4 5
1 2
2 3
1 3
3 4
1 4

TAK

## 题解：

hzwer:

-----------------------------------------------------------------------------------------------------------

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 100000+100
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 using namespace std;
23 {
24     int x=0,f=1;char ch=getchar();
25     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
26     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
27     return x*f;
28 }
29 int n,m,fa[maxn];
30 bool mark[maxn];
31 inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);};
32 int main()
33 {
34     freopen("input.txt","r",stdin);
35     freopen("output.txt","w",stdout);
37     for1(i,n)fa[i]=i;
38     for1(i,m)
39      {
41          if(x==y)mark[x]=1;else fa[x]=y,mark[y]=mark[x]||mark[y];
42      }
43     for1(i,n)if(!mark[find(i)]){cout<<"NIE"<<endl;return 0;}
44     cout<<"TAK"<<endl;
45     return 0;
46 }
View Code

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 1000000
14 #define maxm 1000000
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 using namespace std;
23 {
24     int x=0,f=1;char ch=getchar();
25     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
26     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
27     return x*f;
28 }
30 bool v[maxn];
31 struct edge{int from,next,go,v;}e[2*maxm];
33 void insert(int x,int y,int z){ins(x,y,z);ins(y,x,0);}
34 bool bfs()
35 {
36     for(int i=s;i<=t;i++)h[i]=-1;
37     int l=0,r=1;q[1]=s;h[s]=0;
38     while(l<r)
39     {
40         int x=q[++l];
42          if(e[i].v&&h[e[i].go]==-1)
43          {
44              h[e[i].go]=h[x]+1;q[++r]=e[i].go;
45          }
46     }
47     return h[t]!=-1;
48 }
49 int dfs(int x,int f)
50 {
51     if(x==t) return f;
52     int tmp,used=0,i;
54      if(e[i].v&&h[e[i].go]==h[x]+1)
55     {
56         tmp=dfs(e[i].go,min(e[i].v,f-used));
57         e[i].v-=tmp;if(e[i].v)cur[x]=i;
58         e[i^1].v+=tmp;used+=tmp;
59         if(used==f)return f;
60     }
61     if(!used) h[x]=-1;
62     return used;
63 }
64 void dinic()
65 {
66     maxflow=0;
67     while(bfs())
68     {
70     }
71 }
72 int main()
73 {
74     freopen("input.txt","r",stdin);
75     freopen("output.txt","w",stdout);
77     for1(i,m)
78      {
80          insert(s,i,1);
81          insert(i,m+x,1);insert(i,m+y,1);
82          insert(m+x,m+n+y,1);insert(m+y,m+n+x,1);
83      }
84     for1(i,n)insert(m+n+i,t,1);
85     dinic();
86     if(maxflow==n)cout<<"TAK"<<endl;else cout<<"NIE"<<endl;
87     return 0;
88 }
View Code

posted @ 2014-09-11 15:02  ZYF-ZYF  Views(245)  Comments(0Edit  收藏  举报