TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

100.0% (1/1)

Tags

Description

You are given a directed graph $G$, consisting of $N$ vertices and $M$ edges. The $i$-th edge is directed from $u_ i$ to $v_ i$.

An eulerian circuit of $G$ is a pair of sequence of vertices $(v_ 0,\ldots,v_ {M-1})$ and sequence of edges $(e_ 0,\ldots,e_ {M-1})$ satisfying following conditions.

  • $(e_ 0,\ldots,e_ {M-1})$ is a permutation of $(0, \ldots, M-1)$.
  • For $0\leq i < M-1$, the edge $e_ i$ is directed from $v_ i$ to $v_ {i+1}$. The edge $e_ {M-1}$ is directed from $v_ {M-1}$ to $v_ 0$.

Note that an Eulerian circuit remains an Eulerian circuit after any cyclic shift.

Find the number of Eulerian circuits of $G$, considered the same if they can be obtained from one another by a cyclic shift (in other words, the number of Eulerian circuits with $e_ 0 = 0$), and give the result modulo $998244353$.

Input Format

$N$ $M$
$u_ 0$ $v_ 0$
$\vdots$
$u_ {M-1}$ $v_ {M-1}$

Output Format

Sample Input 1

3 6
0 1
0 1
1 2
1 2
2 0
2 0

Sample Output 1

4

Sample Input 2

4 10
0 1
0 2
1 0
1 3
1 3
2 1
2 3
3 0
3 1
3 2

Sample Output 2

36

Sample Input 3

10 4
0 0
0 0
0 0
0 0

Sample Output 3

6

Sample Input 4

3 2
0 1
1 2

Sample Output 4

0

Hints

  • $1 \leq N \leq 500$
  • $1 \leq M \leq 2 \times 10^ {5}$
  • $0 \leq u_ i, v_ i \lt N$

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 2097152 2097152
1 5000 2097152 2097152
2 5000 2097152 2097152
3 5000 2097152 2097152
4 5000 2097152 2097152
5 5000 2097152 2097152
6 5000 2097152 2097152
7 5000 2097152 2097152
8 5000 2097152 2097152
9 5000 2097152 2097152
10 5000 2097152 2097152
11 5000 2097152 2097152
12 5000 2097152 2097152
13 5000 2097152 2097152
14 5000 2097152 2097152
15 5000 2097152 2097152