Codeforces Round 787 (Div. 3)

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
1675 Codeforces Round 787 (Div. 3) FINISHED False 8100 80061899 May 5, 2022, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 13195 ) D Vertical Paths PROGRAMMING graphs implementation trees

B'You are given a rooted tree consisting of n vertices. Vertices are numbered from 1 to n . Any vertex can be the root of a tree. A tree is a connected undirected graph without cycles. A rooted tree is a tree with a selected vertex, which is called the root. The tree is specified by an array of parents p containing n numbers: p_i is a parent of the vertex with the index i . The parent of a vertex u is a vertex that is the next vertex on the shortest path from u to the root. For example, on the simple path from 5 to 3 (the root), the next vertex would be 1 , so the parent of 5 is 1 . The root has no parent, so for it, the value of p_i is i (the root is the only vertex for which p_i=i ). Find such a set of paths that: For example, if n=5 and p=[3, 1, 3, 3, 1] , then the tree can be divided into three paths: The first line of input data contains an integer t ( 1 <= t <= 10^4 ) -- the number of test cases in the test. Each test case consists of two lines. The first of them contains an integer n ( 1 <= n <= 2 cdot 10^5 ). It is the number of vertices in the tree. The second line contains n integers p_1, p_2, ... , p_n ( 1 <= p_i <= n ). It is guaranteed that the p array encodes some rooted tree. It is guaranteed that the sum of the values n over all test cases in the test does not exceed 2 cdot 10^5 . For each test case on the first line, output an integer m -- the minimum number of non-intersecting leading down paths that can cover all vertices of the tree. Then print m pairs of lines containing path descriptions. In the first of them print the length of the path, in the second -- the sequence of vertices specifying that path in the order from top to bottom. You can output the paths in any order. If there are several answers, output any of them. '...

Tutorials

102550

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
156039205 chenbxxx D May 6, 2022, 4:10 a.m. OK Clang++17 Diagnostics TESTS 10 1793 2969600

remove filters

Back to search problems