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 |
|---|---|---|---|---|---|---|
| 2249 | Codeforces Round 1112 (Div. 1) | FINISHED | False | 9000 | 2388314 | July 26, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 157 ) | F | Even Simple Path | PROGRAMMING | constructive algorithms graphs shortest paths |
You are given a simple undirected graph with (n) vertices and (m) edges. A path is simple if it visits no vertex more than once. The length of a path is the number of edges in it. Find a shortest simple path with even length from vertex (1) to vertex (n), or determine that no such path exists. 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 first line of each test case contains two integers (n) and (m) ((2\le n\le 1000), (0\le m\le \frac{n(n-1)}2)) — the number of vertices and the number of edges in the graph. Then (m) lines follow, the (i)-th line containing two integers (u_i) and (v_i) ((1\le u_i,v_i\le n), (u_i\ne v_i)) — the two vertices that the (i)-th edge connects. It is guaranteed that there are no self-loops or multiple edges in the graph. It is guaranteed that the sum of (n^3) over all test cases does not exceed (1000^3). It is guaranteed that the sum of (m) over all test cases does not exceed (10^6). For each test case, if no such path exists, print (-1). Otherwise, print any shortest simple path of even length from vertex (1) to vertex (n): On the first line, print its length (k); On the second line, print (k+1) vertices (p_0,p_1,\ldots,p_k) in order, where (p_0=1) and (p_k=n). If there are multiple possible answers, you may print any of them. In the first test case, there is no path from vertex (1) to vertex (2), so there is no answer. In the second test case, the path (1 \to 2 \to 3) has length (2), and it is the shortest simple path with even length. In the third test case, the only simple path from vertex (1) to vertex (4) has length (3), which is not even, so there is no answer. In the fourth test case, the path consisting only of the edge (1 \to 5) has length (1), which is odd |
| Codeforces Round 1112 (Div. 1, Div. 2) Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 384452954 | didxga | F | July 27, 2026, 2:06 a.m. | OK | C++17 (GCC 7-32) | TESTS | 174 | 875 | 108646400 | ||
| 384449383 | 1.618 | F | July 27, 2026, 12:56 a.m. | OK | C++17 (GCC 7-32) | TESTS | 174 | 937 | 144384000 | ||
| 384443785 | milky0002 | F | July 26, 2026, 9:33 p.m. | OK | C++17 (GCC 7-32) | TESTS | 174 | 1312 | 262246400 | ||
| 384456730 | zeroliebe | F | July 27, 2026, 3:06 a.m. | OK | C++20 (GCC 13-64) | TESTS | 174 | 546 | 227532800 | ||
| 384435449 | kmsgk | F | July 26, 2026, 7:09 p.m. | OK | C++20 (GCC 13-64) | TESTS | 173 | 656 | 113152000 | ||
| 384421133 | EnuTieTie | F | July 26, 2026, 4:53 p.m. | OK | C++20 (GCC 13-64) | TESTS | 173 | 687 | 257433600 | ||
| 384426548 | Ormlis | F | July 26, 2026, 5:22 p.m. | OK | C++20 (GCC 13-64) | TESTS | 173 | 734 | 229376000 | ||
| 384422106 | Suwan | F | July 26, 2026, 4:56 p.m. | OK | C++20 (GCC 13-64) | TESTS | 173 | 1140 | 257433600 | ||
| 384449809 | Galetx | F | July 27, 2026, 1:05 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 174 | 296 | 16998400 | ||
| 384451756 | permutation | F | July 27, 2026, 1:43 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 174 | 296 | 50380800 | ||
| 384432964 | gausset | F | July 26, 2026, 6:47 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 173 | 390 | 16896000 | ||
| 384418863 | Galetx | F | July 26, 2026, 4:44 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 173 | 390 | 16896000 | ||
| 384448101 | Marckess | F | July 27, 2026, 12:18 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 174 | 500 | 50483200 | ||
| 384406326 | Lynkcat | F | July 26, 2026, 4:03 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 173 | 500 | 78131200 | ||
| 384395733 | 300iq | F | July 26, 2026, 3:38 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 173 | 546 | 86016000 | ||
| 384469056 | molongdadi | F | July 27, 2026, 6:02 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 174 | 578 | 226201600 | ||
| 384444301 | p1k4 | F | July 26, 2026, 9:48 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 174 | 640 | 61132800 | ||
| 384440245 | jeroenodb | F | July 26, 2026, 8:08 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 174 | 671 | 279859200 | ||
| 384422450 | d11maan | F | July 26, 2026, 4:57 p.m. | OK | Rust 2024 | TESTS | 173 | 437 | 149708800 |
Back to search problems