SHARE
TWEET

Untitled

lalalalalalalaalalla Sep 24th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17.  
  18. /*
  19. #pragma GCC optimize("Ofast,no-stack-protector")
  20. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  21. #pragma GCC optimize("unroll-loops")
  22. #pragma GCC optimize("fast-math")
  23. #pragma GCC optimize("section-anchors")
  24. #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  25. #pragma GCC optimize("vpt")
  26. #pragma GCC optimize("rename-registers")
  27. #pragma GCC optimize("move-loop-invariants")
  28. #pragma GCC optimize("unswitch-loops")
  29. #pragma GCC optimize("function-sections")
  30. #pragma GCC optimize("data-sections")
  31. #pragma GCC optimize("branch-target-load-optimize")
  32. #pragma GCC optimize("branch-target-load-optimize2")
  33. #pragma GCC optimize("btr-bb-exclusive")
  34. */
  35.  
  36. #define int long long
  37. #define ll long long
  38. #define ull unsigned long long
  39. #define all(a) a.begin(), a.end()
  40. #define pii pair<int, int>
  41. #define pb push_back
  42. #define ld long double
  43.  
  44.  
  45. using namespace std;
  46.  
  47. const int INF = 1e13;
  48. //const int mod = 2600000069;
  49. //const int p = 179;
  50.  
  51. int n, m;
  52. vector<vector<pii>> g;
  53. vector<int> pos;
  54. vector<int> p;
  55. vector<bool> ban;
  56. pii u;
  57.  
  58. void euler(int v) {
  59.     stack<int> s;
  60.     s.push(v);
  61.     while (!s.empty()) {
  62.         v = s.top();
  63.         while (pos[v] != g[v].size() && ban[g[v][pos[v]].second]) {
  64.             pos[v]++;
  65.         }
  66.         if (pos[v] == g[v].size()) {
  67.             p.pb(v);
  68.             s.pop();
  69.             continue;
  70.         }
  71.         u = g[v][pos[v]];
  72.         ban[u.second] = 1;
  73.         s.push(u.first);
  74.         pos[v]++;
  75.     }
  76. }
  77.  
  78. signed main() {
  79.     ios_base::sync_with_stdio(0);
  80.     cin.tie(0);
  81.     cout.tie(0);
  82.     freopen("painting.in", "r", stdin);
  83.     freopen("painting.out", "w", stdout);
  84. //    cin >> n >> m;
  85. //    g.resize(n);
  86. //    pos.assign(n, 0);
  87. //    ban.assign(m, 0);
  88. //    int a, b;
  89. //    for (int i = 0; i < m; i++) {
  90. //        cin >> a >> b;
  91. //        a--;b--;
  92. //        g[a].pb({b, i});
  93. //        g[b].pb({a, i});
  94. //    }
  95. //    euler(0);
  96. //    for (auto k : p) cout << k << " ";
  97.     cin >> n >> m;
  98.     g.resize(2 * n + 2);
  99.     pos.assign(2 * n + 2, 0);
  100.     vector<pii> c;
  101.     c.resize(m);
  102.     int ind = 0;
  103.     vector<bool> used(2 * n + 2, 0);
  104.     for (int i = 0; i < m; i++) {
  105.         cin >> c[i].first >> c[i].second;
  106.         c[i].first--;
  107.         c[i].second--;
  108.         g[c[i].first].pb({n + c[i].second, ind});
  109.         g[n + c[i].second].pb({c[i].first, ind});
  110.         ind++;
  111. //        if (!used[c[i].first]) {
  112.         g[c[i].first].pb({2 * n, ind});
  113.         g[2 * n].pb({c[i].first, ind});
  114.         ind++;
  115. //        }
  116. //        if (!used[c[i].second + n]) {
  117.         g[c[i].second + n].pb({2 * n + 1, ind});
  118.         g[2 * n + 1].pb({c[i].second + n, ind});
  119.         ind++;
  120. //        }
  121.     }
  122. //    if (m == 1) {
  123. //        cout << "M";
  124. //        return 0;
  125. //    }
  126.     if (g[2 * n].size() % 2) {
  127.         g[2 * n].pb({2 * n + 1, ind});
  128.         g[2 * n + 1].pb({2 * n, ind});
  129.         ind++;
  130.     }
  131.     for (int i = 0; i < 2 * n + 2; i++) {
  132.         sort(all(g[i]));
  133.     }
  134.     ban.assign(ind, 0);
  135.     euler(2 * n);
  136.     int ps = p.size();
  137.     map<pii, string> ans;
  138.     bool color = 0;
  139. //    ans[{p[0], p[ps - 1]}] = (color ? "M" : "W");
  140. //    ans[{p[ps - 1], p[0]}] = (color ? "M" : "W");
  141. //    color = !color;
  142.     for (int i = 1; i < ps; i++) {
  143.         if (p[i] >= 2 * n || p[i - 1] >=  2 * n) continue;
  144.         ans[{p[i], p[i - 1]}] = (color ? "M" : "W");
  145.         ans[{p[i - 1], p[i]}] = (color ? "M" : "W");
  146. //        cout << p[i - 1] << " " << p[i] << " " << color << "\n";
  147.         color = !color;
  148.     }
  149. //    cout << "Here\n";
  150. //    for (auto k : p) cout << k << " ";
  151. //    cout << "\n";
  152.     for (auto k : c) {
  153.         cout << ans[{k.first, k.second + n}];
  154.     }
  155. }
  156. /*
  157. 2 2
  158.  2 1
  159.  1 2
  160.  
  161.  3 5
  162.  1 2
  163.  2 3
  164.  1 3
  165.  2 1
  166.  1 1
  167. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top