Kotlin Heroes: Episode 12

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
2087 Kotlin Heroes: Episode 12 FINISHED False 9000 32369123 April 7, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 26 ) I Hamiltonian Partition PROGRAMMING *special *special

You are given a directed acyclic graph with (n) vertices and (m) edges. The graph contains no cycles or multiple edges. You need to partition all the edges of this graph into Hamiltonian cycles (cycles that visit each of the (n) vertices of the graph exactly once) such that each edge belongs to exactly one cycle. It is obvious that this is impossible for the original graph, so before partitioning, you must add the minimum number of edges to the graph so that such a partition exists. After adding edges, the graph may contain cycles and/or multiple edges, but it should still not have any self-loops. The first line contains two integers (n) and (m) ((2 \le n \le 100); (1 \le m \le \frac{n(n-1)}{2})). The next (m) lines contain two integers (x_i) and (y_i) in the (i)-th line ((1 \le x_i, y_i \le n); (x_i \ne y_i)), representing a directed edge from vertex (x_i) to vertex (y_i). Additional constraints on the input: the given graph has no cycles or multiple edges. In the first line, output a single integer (k) ((1 \le k \le n \cdot m)) — the number of edges you add. Then output (k) lines, in the (i)-th of which there should be two integers (x_i) and (y_i) ((1 \le x_i, y_i \le n); (x_i \ne y_i)), denoting the start and end of the next edge. Then in a single line, output a single integer (c) ((1 \le c \le m)) — the number of Hamiltonian cycles into which you partition all the edges of the graph. In the last line, output (m+k) integers (a_1, a_2, \dots, a_{m+k}) ((1 \le a_i \le c)), where (a_i) is the Hamiltonian cycle to which you assign the (i)-th edge (the edges of the original graph are numbered from (1) to (m), and the new ones are from (m+1) to (m+k)). If there are multiple answers that minimize the number of added edges, output any of them.

Tutorials

141608

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
314404030 ahmedafeef I April 7, 2025, 5:27 p.m. OK Kotlin 1.7 TESTS 66 921 46182400
314400475 tourist I April 7, 2025, 5:02 p.m. OK Kotlin 1.9 TESTS 66 281 2252800

remove filters

Back to search problems