-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVA_10004 - Bicoloring.cpp
67 lines (61 loc) · 1.39 KB
/
UVA_10004 - Bicoloring.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
63
64
65
66
67
#include "bits/stdc++.h"
using namespace std;
typedef long long int LL;
vector <LL> Adj[10000];
vector <bool> visited;
void BFS(LL S, LL N)
{
visited.assign(N,false);
queue <LL> Q;
Q.push(S);
visited[S] = true;
bool flag = true;
while(Q.empty() == false)
{
LL u = Q.front();
Q.pop();
for(int i = 0; i < Adj[u].size(); i++)
{
LL temp = Adj[u][i];
if(visited[temp] == false)
{
if(visited[u] == false)
visited[temp] = true;
else
visited[temp] = false;
Q.push(temp);
}
else if(visited[temp] == true)
{
if(visited[temp] == visited[u])
{
flag = false;
break;
}
}
}
if(flag == false)
break;
}
flag == true ? cout << "BICOLORABLE." << endl : cout << "NOT BICOLORABLE." << endl;
for(int i = 0; i < N; i++)
Adj[i].clear();
}
int main()
{
LL N;
while(scanf("%lld", &N) == 1 and N)
{
LL Len;
scanf("%lld", &Len);
for(int i = 0; i < Len; i++)
{
LL A, B;
scanf("%lld %lld", &A, &B);
Adj[A].push_back(B);
Adj[B].push_back(A);
}
BFS(0,N);
}
return 0;
}