-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10004.cpp
More file actions
executable file
·60 lines (53 loc) · 1.47 KB
/
10004.cpp
File metadata and controls
executable file
·60 lines (53 loc) · 1.47 KB
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
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(true)
{
cin>>n;
if(n==0)break;
else{
int l;
cin>>l;
vector<int>adj[n];
vector<int>color(n+1,-1);
int p,q;
for(int i=0; i<l; i++)
{
cin>>p>>q;
adj[p].push_back(q);
adj[q].push_back(p);
}
queue<int> qu;
bool check =true;
for(int i=0; i<n; i++)
{
if(color[i]==-1)
{
qu.push(i);
color[i]=0;
while(!qu.empty())
{
int v=qu.front();
qu.pop();
for(int u: adj[v])
{
if(color[u]==-1)
{
color[u]=color[v]^1;
qu.push(u);
}
else{
check&=(color[v]!=color[u]);
}
}
}
}
}
cout<<((check)?"BICOLORABLE.":"NOT BICOLORABLE.");
cout<<endl;
}
}
return 0;
}