Advertisement
Guest User

Code

a guest
Sep 5th, 2022
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int adj[5000][5000];
  5. const int mod = 1e9 + 7;
  6.  
  7. int main()
  8. {
  9.     int v, e, q;
  10.     cin >> v >> e >> q;
  11.  
  12.     for (int i = 0; i < e; i++)
  13.     {
  14.         int a, b; cin >> a >> b;
  15.         adj[a][b] = 1;
  16.     }
  17.  
  18.     bool complemented = 0, transposed = 0;
  19.  
  20.     for (int i = 0; i < q; i++)
  21.     {
  22.         int type; cin >> type;
  23.         if (type == 1) v++;
  24.  
  25.         else if (type == 2)
  26.         {
  27.             int x, y; cin >> x >> y;
  28.             if (transposed) swap(x, y);
  29.  
  30.             adj[x][y] = complemented^1;
  31.         }
  32.  
  33.         else if (type == 3)
  34.         {
  35.             int x; cin >> x;
  36.             for (int j = 0; j < v; j++)
  37.             {
  38.                 adj[x][j]= complemented; adj[j][x] = complemented;
  39.             }
  40.         }
  41.         else if (type == 4)
  42.         {
  43.             int x, y; cin >> x >> y;
  44.             if (transposed) swap(x, y);
  45.  
  46.             adj[x][y] = complemented;
  47.         }
  48.  
  49.         else if (type == 5) transposed ^= 1;
  50.         else if (type == 6) complemented ^= 1;
  51.     }
  52.     cout << v << endl;
  53.     for (int x = 0; x < v; x++)
  54.     {
  55.         long long out_degree = 0, hash = 0, counter = 1;
  56.  
  57.         for (int i = 0; i < v; i++)
  58.         {
  59.             if (i == x) continue;
  60.             int cur;
  61.             if (transposed) cur = adj[i][x];
  62.             else cur = adj[x][i];
  63.  
  64.             if (cur == (complemented^1))
  65.             {
  66.                 out_degree++;
  67.                 hash += counter * i; hash %= mod;
  68.                 counter *= 7; counter %= mod;
  69.             }
  70.         }
  71.         cout << out_degree << " " << hash << endl;
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement