File size: 2,187 Bytes
c4b0eef |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define PI(a, b) pair<a, b>
#define MP make_pair
#define EB emplace_back
#define MOD 1000000007
#define int long long int
#define S second
#define F first
#define FOR(var, len) for (var = 0; var < len; var++)
#define debug1 cout << "debug1" << '\n'
#define debug2 cout << "debug2" << '\n'
#define debug3 cout << "debug3" << '\n'
// Maths Utils
int binExp(int a, int b, int m)
{
int r = 1;
while (b)
{
if (b % 2 == 1)
r = (r * a) % m;
a = (a * a) % m;
b = b / 2;
}
return r;
}
vector<int> adj[205];
int color[205];
bool bip(int s)
{
// vis[s] = 1;
color[s] = 0;
queue<int> q;
q.push(s);
int src, des;
while (!q.empty())
{
src = q.front();
q.pop();
for (auto des : adj[src])
{
if (color[des] == color[src])
return false;
else if (color[des] == -1){
color[des] = 1 - color[src];
q.push(des);
}
}
}
return true;
}
int32_t main()
{
fastio;
while (1)
{
int n,m, a, b;
cin>>n;
if(n == 0)break;
cin >> m;
for (int i = 0; i < m; i++)
{
cin >> a >> b;
adj[a].EB(b);
adj[b].EB(a);
}
// for(auto x:adj){
// for(auto y:x)
// cout<<y<<" ";
// cout<<'\n';}
memset(color, -1, sizeof(color));
bool ans = bip(0);
if (ans)
cout << "BICOLORABLE.\n";
else
cout << "NOT BICOLORABLE.\n";
for(int i = 0;i<205;i++)
adj[i].clear();
}
} |