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 |
|---|---|---|---|---|---|---|
| 2164 | Codeforces Global Round 30 (Div. 1 + Div. 2) | FINISHED | False | 10800 | 13965923 | Nov. 6, 2025, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 643 ) | F1 | Chain Prefix Rank (Easy Version) | PROGRAMMING | combinatorics dfs and similar dp math |
This is the easy version of the problem. The difference between the versions is that in this version, (n \le 5000). You can hack only if you solved all versions of this problem. Given a tree (T) with (n) vertices rooted at (1) and a sequence (a) of length (n), count the number of permutations(^{\text{∗}}) (p) of length (n) that satisfy the following condition: For all (1 \le u \le n), there are exactly (a_u) vertices (v) such that (v) is an ancestor of (u) in (T) and (p_v < p_u). Output the answer modulo (998\,244\,353). Input data is selected in such a way that at least one valid permutation exists. (^{\text{∗}})A permutation of length (n) is an array consisting of (n) distinct integers from (1) to (n) in arbitrary order. For example, (2,3,1,5,4) is a permutation, but (1,2,2) is not a permutation ((2) appears twice in the array), and (1,3,4) is also not a permutation ((n=3) but there is (4) in the array). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 2500)). The description of the test cases follows. The first line of each test case contains an integer (n) ((2 \le n \le 5000)) — the number of vertices. The second line of each test case contains (n-1) integers (fa_2,fa_3,\ldots,fa_n) ((1 \le fa_i < i))— (fa_i) is the parent of (i) on (T). The third line of each test case contains (n) integers (a_1,a_2,\ldots,a_n) ((0 \le a_i < n)). It is guaranteed that the sum of (n) over all test cases does not exceed (5000). Input data is selected in such a way that at least one valid permutation exists. For each test case, output one integer — the number of permutations modulo (998\,244\,353). Visualizer link In the first test case, the only permutation which satisfies the condition is (1,2,3,4,5). In the second test case, p |
| Codeforces Global Round 30 Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 347822268 | p6pou | F1 | Nov. 7, 2025, 4:10 a.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 62 | 26112000 | ||
| 347769475 | Zxc200611 | F1 | Nov. 6, 2025, 5:10 p.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 93 | 84582400 | ||
| 347770146 | alireza_kaviani | F1 | Nov. 6, 2025, 5:12 p.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 140 | 56115200 | ||
| 347764706 | ArturSmolenski | F1 | Nov. 6, 2025, 4:55 p.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 155 | 99123200 | ||
| 347816512 | Iron_china | F1 | Nov. 7, 2025, 2:58 a.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 171 | 164454400 | ||
| 347766954 | Rainbow_qwq | F1 | Nov. 6, 2025, 5:02 p.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 187 | 187801600 | ||
| 347821105 | Iron_china | F1 | Nov. 7, 2025, 3:56 a.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 202 | 185344000 | ||
| 347820542 | hzk_cpp | F1 | Nov. 7, 2025, 3:47 a.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 218 | 116121600 | ||
| 347786847 | qwef_ | F1 | Nov. 6, 2025, 7:09 p.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 249 | 232448000 | ||
| 347764636 | Muelsyse | F1 | Nov. 6, 2025, 4:55 p.m. | OK | C++17 (GCC 7-32) | TESTS | 25 | 265 | 201011200 | ||
| 347820329 | phanvinh | F1 | Nov. 7, 2025, 3:44 a.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 62 | 0 | ||
| 347774182 | cqrcqr | F1 | Nov. 6, 2025, 5:25 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 62 | 921600 | ||
| 347763502 | conqueror_of_tourist | F1 | Nov. 6, 2025, 4:52 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 62 | 6656000 | ||
| 347784696 | hxhhxh | F1 | Nov. 6, 2025, 6:50 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 62 | 66150400 | ||
| 347763701 | maxplus | F1 | Nov. 6, 2025, 4:52 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 77 | 204800 | ||
| 347791951 | OG_Matveychick1 | F1 | Nov. 6, 2025, 7:58 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 77 | 14438400 | ||
| 347792385 | OG_Matveychick1 | F1 | Nov. 6, 2025, 8:03 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 77 | 24064000 | ||
| 347816832 | NKheyuxiang | F1 | Nov. 7, 2025, 3:02 a.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 77 | 38092800 | ||
| 347815467 | Thomas0802 | F1 | Nov. 7, 2025, 2:44 a.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 77 | 50483200 | ||
| 347763366 | luanyanjia | F1 | Nov. 6, 2025, 4:51 p.m. | OK | C++20 (GCC 13-64) | TESTS | 25 | 92 | 204800 | ||
| 347798758 | hungchi17 | F1 | Nov. 6, 2025, 9:23 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 61 | 0 | ||
| 347782715 | dumb_boi | F1 | Nov. 6, 2025, 6:33 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 61 | 307200 | ||
| 347822885 | superguymj | F1 | Nov. 7, 2025, 4:18 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 62 | 0 | ||
| 347770522 | keywet06 | F1 | Nov. 6, 2025, 5:13 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 62 | 0 | ||
| 347809523 | wdnmdwrnmmp | F1 | Nov. 7, 2025, 1:20 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 62 | 3993600 | ||
| 347774291 | KrK | F1 | Nov. 6, 2025, 5:25 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 77 | 0 | ||
| 347773278 | ttamx | F1 | Nov. 6, 2025, 5:22 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 77 | 0 | ||
| 347767779 | dreamoon_love_AA | F1 | Nov. 6, 2025, 5:05 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 77 | 5529600 | ||
| 347812638 | cooluo | F1 | Nov. 7, 2025, 2:11 a.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 77 | 32153600 | ||
| 347770970 | PinkieRabbit | F1 | Nov. 6, 2025, 5:15 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 25 | 93 | 204800 | ||
| 347768828 | shade34 | F1 | Nov. 6, 2025, 5:08 p.m. | OK | PyPy 3-64 | TESTS | 25 | 1140 | 88678400 | ||
| 347762822 | Sugar_fan | F1 | Nov. 6, 2025, 4:50 p.m. | OK | Rust 2024 | TESTS | 25 | 2062 | 311808000 |
Back to search problems