Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define endl "\n"
- #define ll long long
- #define PI acos(-1.0)
- #define test cout<<"\n****\n"
- #define LCM(a,b) ((a/__gcd(a,b))*b)
- #define precise fixed(cout);cout<<setprecision(20)
- #define fast ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- vector<int>grap[210];
- char color[210];
- bool BFS(int node,int root){
- memset(color,'*',sizeof(color));
- color[root] = 'R';
- queue<int> que;
- que.push(root);
- while (!que.empty()){
- int parent = que.front();
- que.pop();
- char childColor;
- if(color[parent]=='R'){
- childColor = 'L';
- } else{
- childColor = 'R';
- }
- for (int i = 0; i < grap[parent].size(); i++) {
- int child = grap[parent][i];
- if(color[child]=='*'){
- color[child] = childColor;
- } else if(color[child]==color[parent]){
- return false;
- }else{
- continue;
- }
- que.push(child);
- }
- }
- return true;
- }
- int main() {
- fast;
- int node,edge;
- while (cin>>node && node){
- cin>>edge;
- int nod,ed;
- for(int i=0;i<edge;i++){
- cin>>nod>>ed;
- grap[nod].push_back(ed);
- grap[ed].push_back(nod);
- }
- if(BFS(node,nod)){
- cout<<"BICOLORABLE.\n";
- } else{
- cout<<"NOT BICOLORABLE.\n";
- }
- for (auto& v : grap) {
- v.clear();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement