QOJ.ac

QOJ

时间限制: 5 s 内存限制: 512 MB 总分: 100

#998. Matrix Zeroing

统计

Given an $n \times m$ matrix consisting of $0$s and $1$s, an operation $(x, y)$ is defined as flipping all elements in row $x$ and column $y$ (i.e., $0$ becomes $1$, and $1$ becomes $0$). Note that the element at $(x, y)$ is flipped twice. Initially, all elements in the matrix are $0$. The matrix is first scrambled by performing $k$ operations $(x_1, y_1) \sim (x_k, y_k)$. After scrambling, in each step, a position $(x, y)$ is chosen uniformly at random to perform the operation until the matrix returns to all zeros. Find the expected number of operations required to make the matrix all zeros.

If the expected number of operations is $\frac{P}{Q}$, where $P \ge 0$, $Q > 0$, and $\operatorname{gcd}(P, Q) = 1$, output $PQ^{-1} \bmod 998244353$.

Input

The first line contains three positive integers $n, m, k$.

The following $k$ lines each contain two positive integers $x_i, y_i$, representing the $i$-th operation.

Output

Output the expected number of operations modulo $998244353$.

Examples

Input 1

4 3 5
3 2
2 3
3 1
4 3
4 2

Output 1

63

Note 1

The scrambled matrix looks like this:

1 0 0
0 1 1
1 0 0
1 0 0

Subtasks

  • Subtask 1 ($15\%$): $1 \leq n \times m \leq 1000$;
  • Subtask 2 ($15\%$): $1 \leq n \times m \leq 5000$;
  • Subtask 3 ($20\%$): $1 \leq n, m \leq 500$;
  • Subtask 4 ($20\%$): $1 \leq n, m \leq 2000$;
  • Subtask 5 ($30\%$): $1 \leq n, m \leq 50000$;

For $100\%$ of the data, $1 \leq k \leq 50000$, $1 \leq x_i \leq n$, $1 \leq y_i \leq m$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.