|
||||||||||
Little Devil ITime Limit: 16000/8000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1385 Accepted Submission(s): 504 Problem Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can¡¯t refuse any request from the devil. Also, this devil is looking like a very cute Loli. The devil likes to make thing in chaos. This kingdom¡¯s road system is like simply a tree(connected graph without cycle). A road has a color of black or white. The devil often wants to make some change of this system. In details, we call a path on the tree from a to b consists of vertices lie on the shortest simple path between a and b. And we say an edge is on the path if both its two endpoints is in the path, and an edge is adjacent to the path if exactly one endpoint of it is in the path. Sometimes the devil will ask you to reverse every edge¡¯s color on a path or adjacent to a path. The king¡¯s daughter, WJMZBMR, is also a cute loli, she is surprised by her father¡¯s lolicon-like behavior. As she is concerned about the road-system¡¯s status, sometimes she will ask you to tell there is how many black edge on a path. Initially, every edges is white. Input The first line contains an integer T, denoting the number of the test cases. For each test case, the first line contains an integer n, which is the size of the tree. The vertices be indexed from 1. On the next n-1 lines, each line contains two integers a,b, denoting there is an edge between a and b. The next line contains an integer Q, denoting the number of the operations. On the next Q lines, each line contains three integers t,a,b. t=1 means we reverse every edge¡¯s color on path a to b. t=2 means we reverse every edge¡¯s color adjacent to path a to b. t=3 means we query about the number of black edge on path a to b. T<=5. n,Q<=10^5. Please use scanf,printf instead of cin,cout,because of huge input. Output For each t=3 operation, output the answer in one line. Sample Input
Sample Output
Hint reverse color means change from white to black or vice virsa. Author WJMZBMR Source | ||||||||||
|