原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6324
题意:开始理解树树的遍历,后来推了一会,发现只有Q和D两种情况,只要把给的值扫一遍求异或为零就是D否则就是Q,
不用管连通问题
#include <iostream>
#include <cstdio>
#include <set>
#include <cstring>
#define MAXN 100100
using namespace std;
int f[MAXN];
int n, tree[MAXN], x, y, amount[MAXN];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
memset(amount, 0, sizeof(amount));
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &tree[i]);
}
int sum = tree[0];
for(int i = 0; i < n-1; i++)
{
scanf("%d %d", &x, &y);
}
for(int i = 1; i < n; i++)
{
sum ^= tree[i];
}
if(sum == 0)
cout << 'D' << endl;
else
cout << 'Q' << endl;
}
}