Advertisement
erek1e

Dead Drop Gorgeous - BIO 2022 Round 2

Mar 28th, 2023 (edited)
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     freopen("input.txt", "r", stdin);
  7.     freopen("output.txt", "w", stdout);
  8.     int n; cin >> n;
  9.     vector<int> g[2][2]; // bipartate graph between rows and columns
  10.     /* g[i][j][k] specifies edges in the following way:
  11.      i = 0 when the edge is from row to column and 1 when vice versa
  12.      j = 0 when edge is an alpha and 1 when edge is a beta
  13.      k = the index of the col/row connected to this row/col by this edge
  14.     */
  15.     for (int i = 0; i < 2; ++i) {
  16.         for (int j = 0; j < 2; ++j) g[i][j].resize(n);
  17.     }
  18.     for (int i = 0; i < n; ++i) {
  19.         int x, y; cin >> x >> y;
  20.         g[1][0][x] = y;
  21.         g[0][0][y] = x;
  22.     }
  23.     for (int i = 0; i < n; ++i) {
  24.         int x, y; cin >> x >> y;
  25.         g[1][1][x] = y;
  26.         g[0][1][y] = x;
  27.     }
  28.  
  29.     vector<int> p[2];
  30.     p[0].resize(n), p[1].resize(n);
  31.     for (int i = 0; i < n; ++i) p[0][i] = p[1][i] = i;
  32.  
  33.     vector<bool> seenRow(n);
  34.     for (int i = 0; i < n; ++i) {
  35.         if (seenRow[i]) continue;
  36.         int a = i, b = i, side = 0; // side = 0 when on rows and 1 when on columns
  37.         do {
  38.             if (side == 0) seenRow[a] = seenRow[b] = true;
  39.             swap(p[side][a], p[side][b]);
  40.             a = g[side][1][a];
  41.             b = g[side][0][b];
  42.             swap(a, b);
  43.             side = 1-side;
  44.         } while (a != b);
  45.         seenRow[a] = seenRow[b] = true;
  46.     }
  47.  
  48.     for (int &x : p[0]) cout << x << ' ';
  49.     cout << endl;
  50.     for (int &x : p[1]) cout << x << ' ';
  51.     cout << endl;
  52.     return 0;
  53. }
  54.  
Tags: Bio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement