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 |
|---|---|---|---|---|---|---|
| 2247 | Codeforces Round 1111 (Div. 2) | FINISHED | False | 7200 | 2215484 | July 18, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 996 ) | E | Build a Tree | PROGRAMMING | constructive algorithms |
You are given two integers (n) and (k). Construct a tree(^{\text{∗}}) with (n) vertices such that (\sum\limits_{i = 1}^{n} \operatorname{dist}(i, (i \bmod n) + 1) = k)(^{\text{†}}), or determine that no such tree exists. (^{\text{∗}})A tree is a connected graph without cycles. (^{\text{†}})(\operatorname{dist}(i, j)) is the number of edges on the shortest path from vertex (i) to vertex (j) in the tree. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The only line of each test case contains two integers (n) and (k) ((2 \le n \le 2 \cdot 10^5), (0 \le k \le n^2)) — the number of vertices in the tree and the required value of (k). It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, if there is no solution, output (-1). Otherwise, output (n - 1) lines. Each line should contain two integers (u) and (v) ((1 \le u, v \le n)), denoting an edge of the tree. The edges may be output in any order. If there are multiple suitable trees, output any of them. In the first example, the tree consists of the single edge ((1, 2)). Therefore, (\operatorname{dist}(1, 2) + \operatorname{dist}(2, 1) = 1 + 1 = 2). In the second example, one possible tree is shown below. For this tree, (\operatorname{dist}(1, 2) + \operatorname{dist}(2, 3) + \operatorname{dist}(3, 4) + \operatorname{dist}(4, 1) = 1 + 2 + 2 + 1 = 6). In the fourth example, it can be shown that no suitable tree exists. |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 383363848 | binaryfool | E | July 18, 2026, 4:13 p.m. | OK | C# 13 | TESTS | 19 | 109 | 13209600 | ||
| 383375298 | sagankrishnagupta | E | July 18, 2026, 4:49 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 46 | 0 | ||
| 383408243 | Vedant_Asati | E | July 19, 2026, 12:57 a.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383391481 | myfather2211 | E | July 18, 2026, 7:09 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383372114 | AntiBsayer | E | July 18, 2026, 4:33 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383371477 | i_am_bijoy | E | July 18, 2026, 4:31 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383371016 | MSZ9 | E | July 18, 2026, 4:30 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383369523 | ShakeItOff | E | July 18, 2026, 4:26 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383368635 | codernight | E | July 18, 2026, 4:23 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 0 | ||
| 383384462 | eargle | E | July 18, 2026, 5:57 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 102400 | ||
| 383380334 | hanchangseo | E | July 18, 2026, 5:21 p.m. | OK | C++17 (GCC 7-32) | TESTS | 19 | 62 | 102400 | ||
| 383416185 | CraaazyShep | E | July 19, 2026, 3:32 a.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 102400 | ||
| 383365889 | shnva | E | July 18, 2026, 4:18 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 102400 | ||
| 383362997 | noya2 | E | July 18, 2026, 4:10 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 102400 | ||
| 383362443 | Damofeilang | E | July 18, 2026, 4:09 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 102400 | ||
| 383363109 | hajimii | E | July 18, 2026, 4:11 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 409600 | ||
| 383363721 | dimasik06 | E | July 18, 2026, 4:12 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 1228800 | ||
| 383403873 | tswatery2 | E | July 18, 2026, 10:35 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 1433600 | ||
| 383361047 | zeroliebe | E | July 18, 2026, 4:05 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 1638400 | ||
| 383382255 | dfhzzj | E | July 18, 2026, 5:38 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 1740800 | ||
| 383359661 | porzlck | E | July 18, 2026, 4:01 p.m. | OK | C++20 (GCC 13-64) | TESTS | 19 | 46 | 2048000 | ||
| 383370192 | Sakura_xyz | E | July 18, 2026, 4:28 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 31 | 0 | ||
| 383407408 | Kuro_neko | E | July 19, 2026, 12:31 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 0 | ||
| 383400981 | Belal.echo | E | July 18, 2026, 9:24 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 0 | ||
| 383399790 | borisivth | E | July 18, 2026, 8:57 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 0 | ||
| 383417733 | Nycil_Powder | E | July 19, 2026, 3:57 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 102400 | ||
| 383402581 | Bramer_x | E | July 18, 2026, 10:02 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 102400 | ||
| 383400913 | VanshRA | E | July 18, 2026, 9:22 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 102400 | ||
| 383392922 | kevinyu | E | July 18, 2026, 7:22 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 102400 | ||
| 383391193 | gausset | E | July 18, 2026, 7:06 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 102400 | ||
| 383390142 | Sacha | E | July 18, 2026, 6:53 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 19 | 46 | 102400 | ||
| 383360134 | pengin_2000 | E | July 18, 2026, 4:02 p.m. | OK | GNU C11 | TESTS | 19 | 78 | 1638400 | ||
| 383367392 | rainboy | E | July 18, 2026, 4:20 p.m. | OK | GNU C11 | TESTS | 19 | 921 | 1638400 | ||
| 383362334 | friedlogic | E | July 18, 2026, 4:09 p.m. | OK | Go | TESTS | 19 | 62 | 5120000 | ||
| 383369474 | Bitan1234 | E | July 18, 2026, 4:25 p.m. | OK | Java 21 | TESTS | 19 | 218 | 102400 | ||
| 383364283 | WardellCurry | E | July 18, 2026, 4:14 p.m. | OK | Java 21 | TESTS | 19 | 265 | 6246400 | ||
| 383365171 | Pseudoproton | E | July 18, 2026, 4:16 p.m. | OK | Java 8 | TESTS | 19 | 171 | 0 | ||
| 383402680 | apollo | E | July 18, 2026, 10:04 p.m. | OK | Kotlin 1.7 | TESTS | 19 | 562 | 42598400 | ||
| 383363654 | an0n7me | E | July 18, 2026, 4:12 p.m. | OK | OCaml | TESTS | 19 | 125 | 0 | ||
| 383364176 | MrPancake | E | July 18, 2026, 4:14 p.m. | OK | PyPy 3 | TESTS | 19 | 328 | 34201600 | ||
| 383368281 | Love_dp_in_cp | E | July 18, 2026, 4:22 p.m. | OK | PyPy 3 | TESTS | 19 | 390 | 9728000 | ||
| 383385969 | DSKroc | E | July 18, 2026, 6:10 p.m. | OK | PyPy 3 | TESTS | 19 | 406 | 10752000 | ||
| 383408933 | Faithnhope | E | July 19, 2026, 1:15 a.m. | OK | PyPy 3 | TESTS | 19 | 406 | 11059200 | ||
| 383371257 | ok12 | E | July 18, 2026, 4:30 p.m. | OK | PyPy 3 | TESTS | 19 | 406 | 16384000 |
Back to search problems