Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Scary Tree

By oorpib · Limits 1s, 512 MB

Recently Alex has been learning about “Tree” data structure. While he was learning, a question popped up on his mind, “How many child nodes and descendant nodes (subchilds) can be visited from a specific node given root?”. Child nodes A node directly connected to another node when moving away from the root, an immediate descendant. Descendant nodes A node reachable by repeated proceeding from parent to child. Also known as subchild. Input: The first line contains the number of test cases 1<= T<=10. The next line contains N (2<=N<=10000).The next N-1 line contains X Y (1<=X, Y<=N and X≠Y) Where X is the parent of Y. The next line contains number of Query Q (1<=Q<=100000), next Q lines contains a node number P (1<=P<=N). Note that, we will assume that the node 1 is always root. Output: You should output the Case number followed by the number of child nodes and descendant nodes can be visited from node P. See Output formation to understand clearly.

These pictures describes the given test case.

Sample

InputOutput
1
12
1 2
1 3
1 6
2 4
2 5
5 10
5 8
10 11
6 9
6 7
9 12
2
6
2
Case 1:
3
5

Discussion

Statistics


100% Solution Ratio

wajiulEarliest, 3w ago

Mohammad_SohagFastest, 0.0s

RMN_30654Lightest, 918 kB

hanter32Shortest, 656B

Submit

Login to submit

Related Contests

5th CPU CSE Programming Contest Ended at 2020-03-16 09:00:00 +0000 UTC