Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int n;
  8. vector<int> v[202020];
  9. int q[202020];
  10. int h[202020];
  11.  
  12. int main() {
  13.     srand(1337);
  14.     cin >> n;
  15.     for (int i = 0; i < 5; i++) {
  16.         int c;
  17.         cin >> c;
  18.         for (int j = 0; j < c; j++) {
  19.             int a, b;
  20.             cin >> a >> b;
  21.             bool ok = true;
  22.             for (int k = 0; k < v[a].size(); k++) {
  23.                 if (v[a][k] == b) ok = false;
  24.             }
  25.             if (!ok) continue;
  26.             v[a].push_back(b);
  27.             v[b].push_back(a);
  28.         }
  29.     }
  30.     for (int i = 1; i <= n; i++) q[i] = rand()%2;
  31.  
  32.     for (int i = 1; i <= n; i++) h[i] = i;
  33.     for (int i = 1; i <= n; i++) {
  34.         swap(h[i], h[i+rand()%(n-i+1)]);
  35.     }
  36.  
  37.     while (true) {
  38.          bool ok = true;
  39.          for (int x = 1; x <= n; x++) {
  40.             int i = h[x];
  41.             int a = q[i];
  42.             int z = 0;
  43.             for (int j = 0; j < v[i].size(); j++) {
  44.                 if (q[v[i][j]] == a) z++;
  45.             }
  46.             if (z <= 2) continue;
  47.             ok = false;
  48.             q[i] = 1-q[i];
  49.          }
  50.          if (ok) break;
  51.     }
  52.     for (int i = 1; i <= n; i++) {
  53.         if (q[i] == 0) cout << "A";
  54.         else cout << "B";
  55.     }
  56.     cout << "\n";
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement