Submit | All submissions | Best solutions | Back to list |
ADALEMON - Ada and Lemon 1 |
As you might already know, Ada the Ladybug is a farmer. She grows a lemon tree. She wants to pick exactly one lemon (which grows on every leaf of the tree). She is wondering how many distinct trees will remain after harvesting exactly one lemon. Tree is different if they are distinct for each permutation of node labels.
Note that a single node is counted as leaf too.
Input
The first line of input will contain 1 ≤ T ≤ 100, the number of test-cases.
Each of the testcases will contain single integer N, the size of tree.
The next N-1 lines will contain two integers 0 ≤ a, b < N, a ≠ b, the edges of tree.
The sum of N over all test-cases will not exceed 3000.
Output
For each test-case output the number of distinct trees after harvesting exactly one lemon.
Example Input
5 4 0 1 0 2 0 3 4 0 1 1 3 3 2 6 0 2 1 2 2 3 3 5 3 4 7 1 2 0 1 2 3 2 4 3 5 6 5 9 0 1 1 2 2 3 3 4 4 5 2 6 3 7 4 8
Example Output
1 1 1 3 4
Example Input 2
1 11 6 1 3 6 4 3 2 3 0 6 5 2 10 4 8 1 7 10 9 0
Example Output 2
3
Added by: | Morass |
Date: | 2017-10-26 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
hide comments
2017-10-27 14:33:14
@Min_25: Well yes.. at least I agree it would be a good manner to mention it so thank you, I'll add it to the statement ^_^ Have Nice Day! |
|
2017-10-27 11:10:42 Min_25
@Morass A leaf in an unrooted tree is defined as a vertex of degree 1. So, when N = 1, there are no lemons in the tree and we cannot harvest lemons. [ Edit ] It seems that sometimes vertices of degree 0 are also counted as leaves. [ Edit 2 ] Thanks ! Last edit: 2017-10-27 15:05:11 |