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.
Problems
You are given an undirected connected graph with (n) vertices and (m) edges, where (m \le n + 9). Each edge of the graph must be colored with one of three colors numbered from (1) to (3). We say that vertices (u) and (v) are reachable in color (c) if there exists a path from (u) to (v) consisting only of edges of color (c). Determine whether there exists a way to color the edges such that the following conditions are satisfied: for each color, there is at least one edge painted in that color; for every pair of colors (i) and (j) and every pair of vertices (u) and (v), the following holds: if (u) and (v) are reachable in color (i) and (i \lt j), then they are also reachable in color (j). The first line contains one integer (t) ((1 \le t \le 1000)) — the number of test cases. Each test case begins with a line that contains two integers (n) and (m) ((2 \le n \le 3000); (n - 1 \le m \le n + 9)) — the number of vertices and edges in the graph. Each of the next (m) lines of a test case contains two integers (u_i) and (v_i) ((1 \le u_i, v_i \le n), (u_i \ne v_i)) — the endpoints of the (i)-th edge. Additional constraints on the input: the sum of (n) over all test cases does not exceed (3000); in each test case, the graph has no self-loops or multiple edges; in each test case, the graph is connected. For each test case, print the answer as follows: if such an edge coloring exists, print YES ; otherwise, print NO . Each letter may be printed in any case. In the first example, it's possible to paint the (5)-th edge in color (1), the (1)-st and the (4)-th edge in color (2), and all other edges in color (3). |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
390124088 |
Hugo1729 |
F |
Sept. 9, 2026, 4:38 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
102400 |
|
|
|
390089999 |
ZycK |
F |
Sept. 9, 2026, 1:42 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
102400 |
|
|
|
390088723 |
ZycK |
F |
Sept. 9, 2026, 1:42 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
102400 |
|
|
|
390061686 |
JPMM |
F |
Sept. 9, 2026, 10:19 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
102400 |
|
|
|
389973860 |
Midhilesh |
F |
Sept. 8, 2026, 8:20 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
102400 |
|
|
|
389988993 |
Harsh21_0507 |
F |
Sept. 9, 2026, 3:44 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
204800 |
|
|
|
389969746 |
0nsec |
F |
Sept. 8, 2026, 7:10 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
204800 |
|
|
|
389965356 |
subhankarsutradhar2004 |
F |
Sept. 8, 2026, 6:15 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
204800 |
|
|
|
390007395 |
sanb_wky |
F |
Sept. 9, 2026, 8:25 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
1228800 |
|
|
|
390007005 |
sanb_wky |
F |
Sept. 9, 2026, 8:20 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
59 |
46 |
1228800 |
|
|
|
390024512 |
gopal.thecoder |
F |
Sept. 9, 2026, 9:34 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
31 |
409600 |
|
|
|
390007259 |
yizhilenkuchao |
F |
Sept. 9, 2026, 8:23 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
31 |
409600 |
|
|
|
390158461 |
Dark__Seith |
F |
Sept. 10, 2026, 3:43 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390154022 |
yanWy |
F |
Sept. 10, 2026, 1:48 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390132476 |
lyt-715 |
F |
Sept. 9, 2026, 5:46 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390083416 |
masy2011 |
F |
Sept. 9, 2026, 1:36 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390024489 |
Dominator_of_IITJ |
F |
Sept. 9, 2026, 9:34 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390018277 |
Dominator_of_IITJ |
F |
Sept. 9, 2026, 9:27 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390005062 |
Irrational_pi |
F |
Sept. 9, 2026, 7:53 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
390000477 |
2730883287 |
F |
Sept. 9, 2026, 6:52 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
59 |
46 |
102400 |
|
|
|
389987611 |
hawk.chan |
F |
Sept. 9, 2026, 3:16 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
0 |
|
|
|
390156721 |
WatPz |
F |
Sept. 10, 2026, 3:04 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
390135014 |
Metiscles |
F |
Sept. 9, 2026, 6:12 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
390122796 |
kocieoczy |
F |
Sept. 9, 2026, 4:24 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
390102203 |
heartflow |
F |
Sept. 9, 2026, 2:35 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
390075624 |
jiangly |
F |
Sept. 9, 2026, 12:48 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
390069452 |
GOTKAKO |
F |
Sept. 9, 2026, 11:50 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
390062088 |
Water-OR |
F |
Sept. 9, 2026, 10:25 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
389996402 |
A_G |
F |
Sept. 9, 2026, 6:02 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
389984574 |
tensorcore |
F |
Sept. 9, 2026, 1:55 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
59 |
46 |
102400 |
|
|
|
389975769 |
KAVTHI3125 |
F |
Sept. 8, 2026, 9 p.m. |
OK |
Go |
TESTS |
59 |
46 |
6348800 |
|
|
|
389961005 |
surushuruthi |
F |
Sept. 8, 2026, 5:32 p.m. |
OK |
Java 21 |
TESTS |
59 |
234 |
614400 |
|
|
|
390159713 |
man-ray |
F |
Sept. 10, 2026, 4:03 a.m. |
OK |
Java 21 |
TESTS |
59 |
250 |
1331200 |
|
|
|
389998206 |
iam_bk |
F |
Sept. 9, 2026, 6:23 a.m. |
OK |
Java 21 |
TESTS |
59 |
265 |
1843200 |
|
|
|
390071631 |
kembu |
F |
Sept. 9, 2026, 12:12 p.m. |
OK |
Java 8 |
TESTS |
59 |
187 |
0 |
|
|
|
389990786 |
samchen123 |
F |
Sept. 9, 2026, 4:18 a.m. |
OK |
PyPy 3-64 |
TESTS |
59 |
140 |
7065600 |
|
|
|
390154717 |
ramumali2002 |
F |
Sept. 10, 2026, 2:09 a.m. |
OK |
PyPy 3-64 |
TESTS |
59 |
156 |
5324800 |
|
|
|
389990812 |
samchen123 |
F |
Sept. 9, 2026, 4:19 a.m. |
OK |
PyPy 3-64 |
TESTS |
59 |
234 |
10547200 |
|
|
|
390101246 |
Gleefre |
F |
Sept. 9, 2026, 2:26 p.m. |
OK |
PyPy 3-64 |
TESTS |
59 |
500 |
10137600 |
|
|
|
389972125 |
guesttttter |
F |
Sept. 8, 2026, 7:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
59 |
609 |
11878400 |
|
|
|
390081830 |
BeforeRedemption |
F |
Sept. 9, 2026, 1:32 p.m. |
OK |
PyPy 3-64 |
TESTS |
59 |
2250 |
10854400 |
|
|
|
389965563 |
Faizyab |
F |
Sept. 8, 2026, 6:17 p.m. |
OK |
Python 3 |
TESTS |
59 |
78 |
1638400 |
|
|
|
390064295 |
code.demon |
F |
Sept. 9, 2026, 10:53 a.m. |
OK |
Python 3 |
TESTS |
59 |
93 |
1740800 |
|
|
|
389975226 |
abhishekraj0029 |
F |
Sept. 8, 2026, 8:48 p.m. |
OK |
Python 3 |
TESTS |
59 |
1421 |
1945600 |
|
|
|
389986924 |
lowestx9 |
F |
Sept. 9, 2026, 2:59 a.m. |
OK |
Python 3 |
TESTS |
59 |
1796 |
5120000 |
|
|
|
390062709 |
Egor |
F |
Sept. 9, 2026, 10:33 a.m. |
OK |
Rust 2024 |
TESTS |
59 |
2609 |
0 |
|
|
remove filters
Back to search problems