Raslboyy

Красно-синий граф

Apr 8th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. //#pragma GCC optimize("O3")
  4. //#pragma GCC optimize("unroll-loops")
  5.  
  6. #define mp make_pair
  7. #define pb push_back
  8. #define eb emplace_back
  9. #define x first
  10. #define y second
  11. //#define sz(x) (int)x.size()
  12. #define all(x) begin(x), end(x)
  13. #define rall(x) rbegin(x), rend(x)
  14. #define FOR(i,a,b) for (int i = (a); i < (b); i++)
  15. #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
  16.  
  17. using namespace std;
  18.  
  19. typedef unsigned long long ull;
  20. typedef long long ll;
  21. typedef long double ld;
  22. typedef pair<int, int> pi;
  23. typedef pair<ld, ld> pld;
  24. typedef pair<ll, ll> pl;
  25. typedef vector<int> veci;
  26. typedef vector<bool> vecb;
  27. typedef vector<vector<int>> vvi;
  28. typedef vector<vector<bool>> vvb;
  29.  
  30. const int INF_I = 1e9;
  31. const ll INF_LL = 1e18;
  32. const int MOD = 1000000007;
  33. const double eps = 1e-6;
  34.  
  35. vector<vector<short>> g;
  36. vector<char> c;
  37. int n;
  38.  
  39. bool dfs(int v){
  40.     if (v >= n)
  41.         while(1){}
  42.     c[v] = 1;
  43.     for (int i : g[v]){
  44.         if (c[i] == 0) {
  45.             if (dfs(i))
  46.                 return true;
  47.         }
  48.         else if (c[i] == 1)
  49.             return true;
  50.     }
  51.     c[v] = 2;
  52.     return false;
  53. }
  54.  
  55. int main() {
  56.  
  57.     ios::sync_with_stdio(false);
  58.     cin.tie(nullptr);
  59.     cout.tie(nullptr);
  60.  
  61.     cin >> n;
  62.     g.assign(n, vector<short>());
  63.     c.assign(n, 0);
  64.     for (int i = 0; i < n-1; i++){
  65.         for (int j = 0; j < n-i-1; j++){
  66.             char ch;
  67.             cin >> ch;
  68.             if (ch == 'B')
  69.                 g[i].eb(i+j+1);
  70.             else
  71.                 g[i+j+1].eb(i);
  72.         }
  73.     }
  74.  
  75.     for (int i = 0; i < n; i++)
  76.         if (c[i] == 0 && dfs(i)) {
  77.             cout << "NO\n";
  78.             return 0;
  79.         }
  80.     cout << "YES\n";
  81.  
  82.     return 0;
  83. }
Add Comment
Please, Sign In to add comment