|
||||||||||
Tri-warTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 781 Accepted Submission(s): 252 Problem Description Three countries, Red, Yellow, and Blue are in war. The map of battlefield is a tree, which means that there are N nodes and (N ¨C 1) edges that connect all the nodes. Each country has a base station located in one node. All three countries will not place their station in the same node. And each country will start from its base station to occupy other nodes. For each node, country A will occupy it iff other two country's base stations have larger distances to that node compared to country A. Note that each edge is of the same length. Given three country's base station, you task is to calculate the number of nodes each country occupies (the base station is counted). Input The input starts with a single integer T (1 ¡Ü T ¡Ü 10), the number of test cases. Each test cases starts with a single integer N (3 ¡Ü N ¡Ü 10 ^ 5), which means there are N nodes in the tree. Then N - 1 lines follow, each containing two integers u and v (1 ¡Ü u, v ¡Ü N, u ¡Ù v), which means that there is an edge between node u and node v. Then a single integer M (1 ¡Ü M ¡Ü 10 ^ 5) follows, indicating the number of queries. Each the next M lines contains a query of three integers a, b, c (1 ¡Ü a, b, c ¡Ü N, a, b, c are distinct), which indicates the base stations of the three countries respectively. Output For each query, you should output three integers in a single line, separated by white spaces, indicating the number of nodes that each country occupies. Note that the order is the same as the country's base station input. Sample Input
Sample Output
Source | ||||||||||
|