Advertisement
IlidanBabyRage

rbgraph.cpp

Jun 16th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int NONE = 0;
  6. const int RED = 1;
  7. const int BLUE = 2;
  8.  
  9. int n;
  10. int colors[5000] = {};
  11. int mat[5000][5000] = {};
  12. bool YES = true;
  13.  
  14. void ds(int k, int type);
  15.  
  16. int main(){
  17.  
  18.     cin >> n;
  19.     char tmpc;
  20.  
  21.     for (int i = 1; i < n; i++)
  22.         for (int j = i; j < n; j++){
  23.             cin >> tmpc;
  24.             if (tmpc == 'R')
  25.                 mat[i - 1][j] = RED;
  26.             else
  27.                 mat[i - 1][j] = BLUE;
  28.         }
  29.  
  30.     for (int i = 0; i < n; i++){
  31.         ds(i, NONE);
  32.         for (int j = 0; j < n; j++)
  33.             colors[j] = NONE;
  34.     }
  35.     if (YES)
  36.         cout << "YES" << endl;
  37.     else
  38.         cout << "NO" << endl;
  39.  
  40.     return 0;
  41. }
  42.  
  43. void ds(int k, int type){
  44.     if (colors[k] == NONE){
  45.         colors[k] = type;
  46.     }else{
  47.         if (colors[k] != type && type != NONE){
  48.             YES = false;
  49.             return;
  50.         }
  51.     }
  52.     for (int i = k + 1; i < n; i++){
  53.         if (mat[k][i] == type || type == NONE)
  54.             ds(i, mat[k][i]);
  55.         if (!YES)
  56.             break;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement