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 |
---|---|---|---|---|---|---|
1781 | VK Cup 2022 - Отборочный раунд (Engine) | FINISHED | False | 10800 | 63482063 | Jan. 15, 2023, 12:05 p.m. |
Solved$ |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
---|---|---|---|---|---|---|
( 235 ) | G | Diverse Coloring | PROGRAMMING | trees |
B"In this problem, we will be working with rooted binary trees. A tree is called a rooted binary tree if it has a fixed root and every vertex has at most two children. Let's assign a color -- white or blue -- to each vertex of the tree, and call this assignment a coloring of the tree. Let's call a coloring diverse if every vertex has a neighbor (a parent or a child) colored into an opposite color compared to this vertex. It can be shown that any tree with at least two vertices allows a diverse coloring. Let's define the disbalance of a coloring as the absolute value of the difference between the number of white vertices and the number of blue vertices. Now to the problem. Initially, the tree consists of a single vertex with the number 1 which is its root. Then, for each i from 2 to n , a new vertex i appears in the tree, and it becomes a child of vertex p_i . It is guaranteed that after each step the tree will keep being a binary tree rooted at vertex 1 , that is, each vertex will have at most two children. After every new vertex is added, print the smallest value of disbalance over all possible diverse colorings of the current tree. Moreover, after adding the last vertex with the number n , also print a diverse coloring with the smallest possible disbalance as well. Each test contains multiple test cases. The first line contains the number of test cases t ( 1 <= t <= 10^4 ). The 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 vertices in the final tree. The second line contains n-1 integers p_2, p_3, ldots, p_n ( 1 <= p_i <= i - 1 ) -- the numbers of parents of vertices 2, 3, ldots, n . No integer appears more than twice among p_2, p_3, ldots, p_n . It is guaranteed that the sum of n over all test cases does not exceed 2 cdot 10^5 . For each te"... |
Tutorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
---|---|---|---|---|---|---|---|---|---|---|---|
189349775 | 353cerega | G | Jan. 15, 2023, 2:34 p.m. | OK | GNU C++17 (64) | TESTS | 26 | 826 | 113971200 | ||
189396584 | njwrz | G | Jan. 16, 2023, 4:53 a.m. | OK | GNU C++20 (64) | TESTS | 26 | 62 | 23244800 | ||
189349917 | orz | G | Jan. 15, 2023, 2:34 p.m. | OK | GNU C++20 (64) | TESTS | 26 | 109 | 40448000 | ||
189382320 | Ormlis | G | Jan. 15, 2023, 9:35 p.m. | OK | GNU C++20 (64) | TESTS | 26 | 155 | 42905600 | ||
189385303 | SomethingNew | G | Jan. 15, 2023, 11:32 p.m. | OK | GNU C++20 (64) | TESTS | 26 | 155 | 52019200 | ||
189399314 | DataStructures | G | Jan. 16, 2023, 5:44 a.m. | OK | GNU C++20 (64) | TESTS | 26 | 280 | 42803200 | ||
189345101 | never_giveup | G | Jan. 15, 2023, 2:13 p.m. | OK | GNU C++20 (64) | TESTS | 26 | 638 | 143769600 |
Back to search problems