Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv)
- {
- int t, n, x;
- cin >> t;
- while (t--) {
- cin >> n >> x;
- vector<vector<int>> g(n + 1);
- for (int i = 1; i < n; ++i) {
- int x, y;
- cin >> x >> y;
- g[x].push_back(y), g[y].push_back(x);
- }
- vector<int> cnt(n + 1);
- function<int(int, int)> dfs = [&](int u, int fa) {
- int ret = 1;
- for (auto v : g[u]) {
- if (v == fa)
- continue;
- // ret ^= dfs(v, u) % 2;
- ret += dfs(v, u);
- }
- return cnt[u] = ret;
- };
- dfs(x, -1);
- int xsum = 0;
- for (auto v : g[x]) {
- xsum ^= cnt[v];
- }
- bool ans = false;
- for (auto v : g[x]) {
- ans |= (cnt[v] % 2) ^ (xsum ^ cnt[v]);
- }
- // cout << (ans ? "lose" : "win") << endl;
- cout << (g[x].size() == 1 || (cnt[x] - 1) % 2 ? "win" : "lose") << endl;
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement