Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. vector <vector<bool> > g;
  8. vector <bool> nodes, bio;
  9. bool solution=true, color=false;
  10.  
  11. int dfs (int node) {
  12.     color= color==false ? true : false;
  13.     nodes[node]=color;
  14.  
  15.     for (int i=0;i<g[node].size();i++)
  16.             if (g[node][i]==1 && bio[i]==false) {
  17.             bio[i]=true;
  18.             dfs (i); }
  19.     color= color==false ? true : false;
  20.     }
  21.  
  22.  
  23. void read (int n) {
  24.     solution=true;
  25.     int l;
  26.     scanf ("%d", &l);
  27.  
  28.     nodes.clear (); g.clear (); bio.clear();
  29.     nodes.resize (n, false);
  30.     bio.resize (n, false);
  31.     g.resize (n, nodes);
  32.  
  33.     for (int i=0;i<l;i++) {
  34.         int a, b;
  35.         scanf ("%d %d", &a, &b);
  36.         g[a][b]=g[b][a]=true;
  37.     }
  38.     bio[0]=true;
  39.     dfs (0);
  40.  
  41.     for (int i=0;i<n-1;i++) {
  42.         for (int j=i+1;j<n;j++) {
  43.             if (g[i][j]==true && nodes[i]==nodes[j]) solution=false; } }
  44. }
  45.  
  46. int main () {
  47.         //freopen ("readfile.in", "r", stdin);
  48.     int n;
  49.  
  50.     while (scanf ("%d", &n)==1 && n!=0) {
  51.             read (n);
  52.            printf (solution==false ? "NOT BICOLORABLE.\n" : "BICOLORABLE.\n");
  53.     }
  54. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement