-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10004.cpp
62 lines (56 loc) · 1.1 KB
/
10004.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
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
struct graph
{
vector<int> *adj;
int len;
graph(int n)
{
adj = new vector<int>[n];
len = n;
};
};
int color[205];
bool dfs(graph g,int v)
{
int u;
for(int i=0;i<g.adj[v].size();i++)
{
if(!color[g.adj[v][i]])
{
color[g.adj[v][i]] = -color[v];
if(!dfs(g,g.adj[v][i]))
{
return false;
}
}
else
{
if(color[g.adj[v][i]] == color[v])
return false;
}
}
return true;
}
int main()
{
int n,t,l,a,b;
while(scanf("%d",&n)&&n)
{
scanf("%d",&l);
memset(color,0,sizeof(int)*205);
graph g(n);
for(int i=0;i<l;i++)
{
scanf("%d%d",&a,&b);
g.adj[a].push_back(b);
g.adj[b].push_back(a);
}
color[0] = true;
if(!dfs(g,0))
cout<<"NOT ";
cout<<"BICOLORABLE."<<endl;
delete[] g.adj;
}
return 0;
}