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
In Zhuji, a city in central Zhejiang Province, local folklore tells of a wild beast known as the Modeiyon . Dwelling deep in the mountains, it is said to sneak into villages at night to devour livestock and prey on lone travelers. Though many elders claim to have seen it, no photograph of the creature has ever been taken. A brave group of (m) people decides to head up the mountain to hunt the beast. The mountain's locations and trails can be modeled as a functional graph (G) with (n) vertices (numbered (1) to (n)). A functional graph is a directed graph with (n) vertices and (n) edges, where every vertex has an out-degree of exactly (1). Additionally, it is known that the mountain's trails do not ever form self-loops . The group will choose exactly (m) distinct vertices to form their initial starting set (S). A starting set (S) is defined as successful if every vertex (u) in the graph is reachable from at least one vertex (v \in S) (a vertex is always reachable from itself). There are (\binom{n}{m}) possible ways to choose the starting set of size (m). They define the value of a graph (G) as the number of successful starting sets it has. However, the exact layout of the mountain's trails is unknown. If the destination of the single outgoing edge from each vertex is chosen arbitrarily from the remaining (n-1) vertices (excluding the vertex itself), there are exactly ((n-1)^n) possible functional graphs. Given (n) and (m), your task is to calculate the sum of the values of all ((n-1)^n) possible functional graphs. Since the answer can be very large, print it modulo (998\,244\,353). 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,m) ((1\le m \le n\le 10^6)) — the number of vertices in the grap |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
380363339 |
-firefly- |
D |
June 27, 2026, 4:27 p.m. |
OK |
C# 13 |
TESTS |
16 |
250 |
10240000 |
|
|
|
380381242 |
oceeff |
D |
June 27, 2026, 7:05 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
281 |
10137600 |
|
|
|
380354247 |
11231123 |
D |
June 27, 2026, 3:51 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
312 |
8089600 |
|
|
|
380347260 |
LLI_E_P_JI_O_K |
D |
June 27, 2026, 3:30 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
312 |
16896000 |
|
|
|
380414244 |
studyyyzz |
D |
June 28, 2026, 5:02 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
328 |
16076800 |
|
|
|
380370374 |
Gmt.FFF |
D |
June 27, 2026, 5:03 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
343 |
16076800 |
|
|
|
380356753 |
16204 |
D |
June 27, 2026, 4 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
343 |
16076800 |
|
|
|
380360549 |
_paper_ |
D |
June 27, 2026, 4:15 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
359 |
16076800 |
|
|
|
380364861 |
sunchenyu2012 |
D |
June 27, 2026, 4:34 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
359 |
64102400 |
|
|
|
380357732 |
David-M |
D |
June 27, 2026, 4:04 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
375 |
16076800 |
|
|
|
380344736 |
_annhien_ruby22 |
D |
June 27, 2026, 3:23 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
16 |
375 |
16076800 |
|
|
|
380418112 |
dumb_god |
D |
June 28, 2026, 6:05 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
62 |
85401600 |
|
|
|
380409393 |
Milkcat2009 |
D |
June 28, 2026, 3:18 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
62 |
85401600 |
|
|
|
380372264 |
shiomusubi496 |
D |
June 27, 2026, 5:21 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
78 |
13721600 |
|
|
|
380361810 |
Pirate-King |
D |
June 27, 2026, 4:20 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
78 |
40140800 |
|
|
|
380372813 |
YangWithin |
D |
June 27, 2026, 5:26 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
93 |
12083200 |
|
|
|
380351766 |
bismispis |
D |
June 27, 2026, 3:43 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
93 |
12083200 |
|
|
|
380366799 |
zhy1206 |
D |
June 27, 2026, 4:44 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
93 |
16076800 |
|
|
|
380364473 |
EricZzzzz |
D |
June 27, 2026, 4:32 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
93 |
16076800 |
|
|
|
380370647 |
Anoth3r |
D |
June 27, 2026, 5:04 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
93 |
36147200 |
|
|
|
380371941 |
shiomusubi496 |
D |
June 27, 2026, 5:18 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
16 |
109 |
4812800 |
|
|
|
380398420 |
PinkieRabbit |
D |
June 27, 2026, 10:11 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
62 |
9318400 |
|
|
|
380368028 |
orange_man |
D |
June 27, 2026, 4:51 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
78 |
4198400 |
|
|
|
380368544 |
P2441M |
D |
June 27, 2026, 4:53 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
78 |
8089600 |
|
|
|
380357780 |
Gold_Dino |
D |
June 27, 2026, 4:04 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
78 |
12185600 |
|
|
|
380416654 |
the_main_question_is_why |
D |
June 28, 2026, 5:42 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
78 |
17408000 |
|
|
|
380379949 |
stevenwjy |
D |
June 27, 2026, 6:48 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
93 |
4198400 |
|
|
|
380367283 |
Imdie |
D |
June 27, 2026, 4:46 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
93 |
12083200 |
|
|
|
380358779 |
StevenKnight |
D |
June 27, 2026, 4:08 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
93 |
12083200 |
|
|
|
380355052 |
Milmon |
D |
June 27, 2026, 3:54 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
93 |
12083200 |
|
|
|
380347773 |
SanceiLaks |
D |
June 27, 2026, 3:31 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
16 |
93 |
12185600 |
|
|
|
380355070 |
hos.lyric |
D |
June 27, 2026, 3:54 p.m. |
OK |
D |
TESTS |
16 |
1875 |
44544000 |
|
|
|
380356619 |
gofrozen21 |
D |
June 27, 2026, 4 p.m. |
OK |
Java 21 |
TESTS |
16 |
546 |
18329600 |
|
|
|
380365322 |
LT1 |
D |
June 27, 2026, 4:37 p.m. |
OK |
Java 21 |
TESTS |
16 |
1015 |
19558400 |
|
|
|
380377471 |
Kraken24 |
D |
June 27, 2026, 6:16 p.m. |
OK |
Java 21 |
TESTS |
16 |
1343 |
18534400 |
|
|
|
380363919 |
hardgonnapass |
D |
June 27, 2026, 4:30 p.m. |
OK |
Java 8 |
TESTS |
16 |
265 |
14950400 |
|
|
|
380361940 |
bitplease_ |
D |
June 27, 2026, 4:21 p.m. |
OK |
Node.js |
TESTS |
16 |
421 |
22220800 |
|
|
|
380382434 |
Puddles_Penguin |
D |
June 27, 2026, 7:17 p.m. |
OK |
PyPy 3-64 |
TESTS |
16 |
1328 |
20787200 |
|
|
|
380366388 |
harurun4635 |
D |
June 27, 2026, 4:42 p.m. |
OK |
PyPy 3-64 |
TESTS |
16 |
1421 |
23552000 |
|
|
|
380362785 |
Mentholzzz |
D |
June 27, 2026, 4:24 p.m. |
OK |
PyPy 3-64 |
TESTS |
16 |
1484 |
26419200 |
|
|
|
380368021 |
maworkin |
D |
June 27, 2026, 4:50 p.m. |
OK |
Python 3 |
TESTS |
16 |
1687 |
20889600 |
|
|
|
380369630 |
cvs-650 |
D |
June 27, 2026, 4:59 p.m. |
OK |
Rust 2024 |
TESTS |
16 |
109 |
12288000 |
|
|
|
380362166 |
Egor |
D |
June 27, 2026, 4:22 p.m. |
OK |
Rust 2024 |
TESTS |
16 |
218 |
6860800 |
|
|
remove filters
Back to search problems