Advertisement
pb_jiang

jd笔试题

Sep 17th, 2023
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  8.  
  9. using ll = long long;
  10. using pii = pair<int, int>;
  11. using pll = pair<ll, ll>;
  12. using vl = vector<ll>;
  13. using vi = vector<int>;
  14.  
  15. int main(int argc, char **argv)
  16. {
  17.     int t, n, x;
  18.     cin >> t;
  19.     while (t--) {
  20.         cin >> n >> x;
  21.         vector<vector<int>> g(n + 1);
  22.         for (int i = 1; i < n; ++i) {
  23.             int x, y;
  24.             cin >> x >> y;
  25.             g[x].push_back(y), g[y].push_back(x);
  26.         }
  27.         vector<int> cnt(n + 1);
  28.         function<int(int, int)> dfs = [&](int u, int fa) {
  29.             int ret = 1;
  30.             for (auto v : g[u]) {
  31.                 if (v == fa)
  32.                     continue;
  33.                 // ret ^= dfs(v, u) % 2;
  34.                 ret += dfs(v, u);
  35.             }
  36.             return cnt[u] = ret;
  37.         };
  38.         dfs(x, -1);
  39.         int xsum = 0;
  40.         for (auto v : g[x]) {
  41.             xsum ^= cnt[v];
  42.         }
  43.         bool ans = false;
  44.         for (auto v : g[x]) {
  45.             ans |= (cnt[v] % 2) ^ (xsum ^ cnt[v]);
  46.         }
  47.         // cout << (ans ? "lose" : "win") << endl;
  48.         cout << (g[x].size() == 1 || (cnt[x] - 1) % 2 ? "win" : "lose") << endl;
  49.     }
  50.     return 0;
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement