-
Notifications
You must be signed in to change notification settings - Fork 2
/
UVA 11396 - Claw Decomposition.cpp
56 lines (51 loc) · 1.09 KB
/
UVA 11396 - Claw Decomposition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vii vector< vector<int> >
vii adj;
int vis[310];
bool bfs(int s)
{
vis[s] = 1;
queue<int> q;
q.push(s);
while(!q.empty()){
int u = q.front(); q.pop();
for(int i=0; i<adj[u].size(); i++){
int v = adj[u][i];
if(!vis[v]){
vis[v] = 3 - vis[u];
q.push(v);
}else if(vis[u] == vis[v]) return false;
}
}
return true;
}
int main()
{
int n;
while(1){
scanf("%d", &n);
if(!n) break;
adj.assign(n+1, vi(0) );
memset(vis, 0, sizeof vis);
int a, b;
while(1){
scanf("%d%d", &a, &b);
if(!a && !b) break;
adj[a].push_back(b);
adj[b].push_back(a);
}
bool ch = 1;
for(int i=1; i<=n; i++){
if(!vis[i]){
if(!bfs(i)){
ch = 0;
break;
}
}
}
if(!ch) printf("NO\n");
else printf("YES\n");
}
}