Codeforces Global Round 16

Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
1566 Codeforces Global Round 16 FINISHED False 9000 105722662 Sept. 12, 2021, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 4221 ) E Buds Re-hanging PROGRAMMING dfs and similar graphs greedy trees

B"A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex v (different from root) is the previous to v vertex on the shortest path from the root to the vertex v . Children of the vertex v are all vertices for which v is the parent. A vertex is a leaf if it has no children. We call a vertex a bud, if the following three conditions are satisfied: You are given a rooted tree with n vertices. The vertex 1 is the root. In one operation you can choose any bud with all its children (they are leaves) and re-hang them to any other vertex of the tree. By doing that you delete the edge connecting the bud and its parent and add an edge between the bud and the chosen vertex of the tree. The chosen vertex cannot be the bud itself or any of its children. All children of the bud stay connected to the bud. What is the minimum number of leaves it is possible to get if you can make any number of the above-mentioned operations (possibly zero)? The input consists of multiple test cases. The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer n ( 2 <= n <= 2 cdot 10^5 ) -- the number of the vertices in the given tree. Each of the next n-1 lines contains two integers u and v ( 1 <= u, v <= n , u neq v ) meaning that there is an edge between vertices u and v in the tree. It is guaranteed that the given graph is a tree. It is guaranteed that the sum of n over all test cases doesn't exceed 2 cdot 10^5 . For each test case print a single integer -- the minimal number of leaves that is possible to get after some operations. In the first test case the tree looks as follows: Firstly you can choose a bud vertex 4 and re-hang it to vertex 3 . After that you can "...

Tutorials

Codeforces Global Round 16 Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
128653026 Gassa E Sept. 12, 2021, 4:28 p.m. OK D TESTS 27 249 24371200

remove filters

Back to search problems