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
This is the easy version of the problem. The difference between the versions is that in this version, you only need to determine whether a valid sequence of operations exists. You can hack only if you solved all versions of this problem. Kevin has an undirected graph with (n) vertices and (m) edges. Initially, some vertices contain stones, which Kevin wants to move to new positions. Kevin can perform the following operation: For each stone at (u_i), select a neighboring vertex (v_i). Simultaneously move each stone from (u_i) to its corresponding (v_i). At any time, each vertex can contain at most one stone. Determine whether a valid sequence of operations exists that moves the stones from the initial state to the target state. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 1000)). The description of the test cases follows. The first line of each test case contains two integers (n) and (m) ((1\leq n \leq 2000), (0\leq m \leq \min(\frac{n(n-1)}{2}, 10^4))) — the number of vertices and edges in the graph. The second line contains a binary string (s) consisting of '0' and '1'. The (i)-th bit of (s) indicates the number of stones on the (i)-th vertex in the initial state. The third line contains a binary string (t) consisting of '0' and '1'. The (i)-th bit of (t) indicates the number of stones on the (i)-th vertex in the target state. Each of the next (m) lines contains two integers (u) and (v) ((1\leq u, v \leq n)) — an undirected edge between the (u)-th vertex and the (v)-th vertex. It is guaranteed that the graph is simple. There are no self-loops and parallel edges in the graph. It is guaranteed that the numbers of '1' in (s) and (t) are the same. It is guaranteed that the sum of (n) over all test cases does not exceed (2000). It is guaranteed that the sum of (m) over all test |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
302135032 |
oleh1421 |
H1 |
Jan. 20, 2025, 6:43 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
86 |
62 |
102400 |
|
|
|
302160003 |
_chroneZ |
H1 |
Jan. 21, 2025, 1:42 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
87 |
62 |
3379200 |
|
|
|
302134419 |
StarSilk |
H1 |
Jan. 20, 2025, 6:39 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
86 |
62 |
5120000 |
|
|
|
302165085 |
Dominater069 |
H1 |
Jan. 21, 2025, 2:58 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
87 |
77 |
102400 |
|
|
|
302128636 |
szilb |
H1 |
Jan. 20, 2025, 5:34 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
86 |
77 |
102400 |
|
|
|
302123846 |
tourist |
H1 |
Jan. 20, 2025, 5:19 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
86 |
77 |
102400 |
|
|
|
302142551 |
244mhq |
H1 |
Jan. 20, 2025, 7:53 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
87 |
77 |
409600 |
|
|
|
302158117 |
rqoi032 |
H1 |
Jan. 21, 2025, 1:08 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
87 |
77 |
716800 |
|
|
|
302137406 |
szilb |
H1 |
Jan. 20, 2025, 7:02 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
87 |
93 |
102400 |
|
|
|
302123275 |
gamegame |
H1 |
Jan. 20, 2025, 5:18 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
86 |
109 |
82227200 |
|
|
|
302177583 |
sakg |
H1 |
Jan. 21, 2025, 5:33 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
87 |
62 |
102400 |
|
|
|
302128311 |
Petr |
H1 |
Jan. 20, 2025, 5:33 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
86 |
62 |
102400 |
|
|
|
302120307 |
Benq |
H1 |
Jan. 20, 2025, 5:08 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
86 |
62 |
102400 |
|
|
|
302162173 |
errorgorn |
H1 |
Jan. 21, 2025, 2:15 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
87 |
77 |
102400 |
|
|
|
302150853 |
tkacper |
H1 |
Jan. 20, 2025, 10:05 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
87 |
77 |
102400 |
|
|
|
302128240 |
ecnerwala |
H1 |
Jan. 20, 2025, 5:33 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
86 |
77 |
102400 |
|
|
|
302160912 |
Kevin114514 |
H1 |
Jan. 21, 2025, 1:56 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
87 |
93 |
1638400 |
|
|
|
302121680 |
arvindf232 |
H1 |
Jan. 20, 2025, 5:12 p.m. |
OK |
Kotlin 1.9 |
TESTS |
86 |
311 |
1843200 |
|
|
|
302122252 |
Egor |
H1 |
Jan. 20, 2025, 5:14 p.m. |
OK |
Rust 2021 |
TESTS |
86 |
77 |
102400 |
|
|
remove filters
Back to search problems