knightnemo commited on
Commit
d3b3ed5
·
verified ·
1 Parent(s): 3d14352

Upload code_segments/segment_93.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. code_segments/segment_93.txt +21 -0
code_segments/segment_93.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Two hungry red pandas, Oscar and Lura, have a tree $T$ with $n$ nodes. They are willing to perform the following shuffle procedure on the whole tree $T$ exactly once. With this shuffle procedure, they will create a new tree out of the nodes of the old tree.
2
+
3
+ 1. Choose any node $V$ from the original tree $T$. Create a new tree $T_2$, with $V$ as the root. 2. Remove $V$ from $T$, such that the original tree is split into one or more subtrees (or zero subtrees, if $V$ is the only node in $T$). 3. Shuffle each subtree with the same procedure (again choosing any node as the root), then connect all shuffled subtrees' roots back to $V$ to finish constructing $T_2$.
4
+
5
+ After this, Oscar and Lura are left with a new tree $T_2$. They can only eat leaves and are very hungry, so please find the maximum number of leaves over all trees that can be created in exactly one shuffle.
6
+
7
+ Note that leaves are all nodes with degree $1$. Thus, the root may be considered as a leaf if it has only one child.
8
+
9
+ The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
10
+
11
+ The first line of every test case contains a single integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the number of nodes within the original tree $T$.
12
+
13
+ The next $n - 1$ lines each contain two integers $u$ and $v$ ($1 \leq u, v \leq n$) — an edge within the original tree $T$. The given edges form a tree.
14
+
15
+ The sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
16
+
17
+ For each test case, output a single integer — the maximum number of leaves achievable with exactly one shuffle procedure on the whole tree.
18
+
19
+ In the first test case, it can be shown that the maximum number of leaves is $4$. To accomplish this, we can start our shuffle with selecting node $3$ as the new root.
20
+
21
+ ![](CDN_BASE_URL/038cb83999c75e319cd6897cdfe03b7b) Next, we are left only with one subtree, in which we can select node $2$ to be the new root of that subtree. ![](CDN_BASE_URL/85eb09dd4b3b98aa44c0450fc1904edf) This will force all $3$ remaining nodes to be l