-
Notifications
You must be signed in to change notification settings - Fork 185
/
10004.cc
43 lines (43 loc) · 789 Bytes
/
10004.cc
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
// https://uva.onlinejudge.org/external/100/10004.pdf
#include<bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using qi=queue<int>;
int main(){
int n,m,u,v;
for(;;){
cin>>n>>m;
if(!n)break;
vvi g(n);
for(int i=0;i<m;i++){
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
vi p(n),c(n);
qi q;
q.push(0);
p[0]=-1;
c[0]=2;
bool ok=1;
while(!q.empty()){
u=q.front();
int z=c[u]%2+1;
q.pop();
for(int k:g[u]){
if(!c[k]){
p[k]=u;
q.push(k);
c[k]=z;
}else if(z!=c[k]){
ok=0;
break;
}
}
if(!ok)break;
}
if(ok)cout<<"BICOLORABLE.\n";
else cout<<"NOT BICOLORABLE.\n";
}
}