Topic Portal (internal title 81)
Input Format
A first line integer $ T (T \ leqslant 20) $, the test data set represents
the next $ T $ group, for each group, a first row of n-$ $ integer
second row has n-$ $ integer, It is $ w_1, w_2 ... w_n $
next $ n-1 $ lines of two integers $ x, y $, indicates there is a connection between the edge and $ X $ $ $ Y
Output Format
For each group, the answer is only one line, if small wins $ Q $ output $ Q $, $ T $ small wins $ T $ output, if the output tie $ D $.
Sample
Sample input:
2
3
2 2 2
1 2
1 3
4
7 1 4 2
1 2
1 3
2 4
Sample output:
Do
D
Data range and tips
Sample explained:
In the first group, the small $ Q $ select any node with a score of $ 2 $, $ T $ small remaining two selected nodes, the score is $ 0 $, $ Q $ small win
in the second set, the small $ Q $ The best and only small $ T $ draw, so the output of $ D $
data range:
For $ 30 \% $ data, $ n \ leqslant 20 $
to 100 $ \% $ data, $ n \ leqslant 100,000, w_i \ leqslant 10 ^ 9 $.
answer
Small $ Q $ certainly can not lose, a draw situation if and only if all of the $ w_i $ XOR and $ 0 $ can occur when, or $ Q $ small must not win.
Because the topic of people out of this problem is intended to get points, so there may be a variety of wrong answers to this question can be (heard on the beat can only withstood $ 6,7 $-point fake $ DP $'ll get $ 90 $ points) ......
Time complexity: $ \ Theta (T \ times n) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
using namespace std;
int n;
int w;
int XOR;
int main()
{
int T;scanf("%d",&T);
while(T--)
{
scanf("%d",&n);XOR=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&w);
XOR^=w;
}
for(int i=1;i<n;i++)
scanf("%d%d",&w,&w);
if(XOR)puts("Q");
else puts("D");
}
return 0;
}
rp++