View Code of Problem 122

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;cin>>t;
	while(t--){
		int n,x,y,f=1;cin>>n;
		vector<int>v[n+2];	
		for(int i=0;i<n-1;++i){
			scanf("%d%d",&x,&y);
			v[x].push_back(y);
			v[y].push_back(x);
		}
		for(auto i:v[1]){
			if(f){
				x=v[i].size();
				f=0;
			}
			else
			x^=v[i].size();
		}
		if(x)
		cout<<"Alice"<<endl;
		else
		cout<<"Bob"<<endl;
	}

}

Double click to view unformatted code.


Back to problem 122