Uva 10004 Solution

#include<bits/stdc++.h>
#define white 1
#define black 2
using namespace std;

int a[205][205], c[205], node, edge;

void bfs()
{
    c[0] = white;
    int f = 1;

    queue<int>q;
    q.push(0);

    while(!q.empty())
    {
        int x = q.front();
        q.pop();

        for(int i=0;i<node;i++)
        {
            if(a[x][i] == 1)
            {
                if(c[x] == white && (c[i] != white && c[i] != black))
                {
                    c[i] = black;
                    q.push(i);
                }
                else if(c[x] == black && (c[i] != white && c[i] != black))
                {
                    c[i] = white;
                    q.push(i);
                }
                else if((c[x] == white && c[i] == black) || (c[x] == black && c[i] == white))
                {
                    continue;
                }
                else if((c[x] == white && c[i] == white) || (c[x] == black && c[i] == black))
                {
                    f = 0;
                    cout << "NOT BICOLORABLE." << "\n";
                    return;
                }
            }
        }
    }
    if(f == 1)
        cout << "BICOLORABLE." << "\n";
}

int main()
{
    int n1, n2, i, j;
    
    while(cin >> node && node != 0)
    {
        for(i=0;i<202;i++)
        {
            c[i] = 0;
            for(j=0;j<202;j++)
            {
                a[i][j] = 0;
            }
        }

        cin >> edge;

        for(i=1;i<=edge;i++)
        {
            cin >> n1 >> n2;
            a[n1][n2] = 1;
            a[n2][n1] = 1;
        }

        bfs();
    }

    return 0;
}

Comments