View Code of Problem 122

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int flag = 1;
        vector<int> v[n + 1];
        for (int i = 0; i < n-1;i++){
            int x, y;
            cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        int ans = 0;
        for(auto vv : v[1]){
            if(flag){
                ans = v[vv].size();
                flag = 0;
            }else
                ans ^= v[vv].size();
        }
        if(ans){
            cout << "Alice" << endl;
        }else
            cout << "Bob" << endl;
    }
}

Double click to view unformatted code.


Back to problem 122