#P5888. 传球游戏

传球游戏

Description

It turns out he is thinking about this problem:

There are nn players standing in a circle, numbered from 11 to nn. At the beginning, the ball is in the hands of player 11. There are mm passes in total. In each pass, the ball must be passed to someone, but it cannot be passed to oneself. Find the number of ways such that after the mm-th pass, the ball is passed back to player 11.

But he thinks this problem is too easy, so he adds kk restrictions. Each restriction is of the form a,ba,b, meaning that player aa cannot pass the ball to player bb.

To bring oql’s attention back to the match as soon as possible, you need to tell him this number of ways in the shortest time.

You only need to output the result modulo 998244353998244353.

Input Format

The input consists of k+1k+1 lines:

The first line contains three integers n,m,kn,m,k, which represent the number of players, the number of passes, and the number of restrictions.

The next kk lines each contain two integers ai,bia_i,b_i, indicating that player aia_i cannot pass the ball to player bib_i.

The data guarantees that there do not exist different i,ji,j such that ai=aja_i=a_j and bi=bjb_i=b_j.

Output Format

Output one integer, representing the number of valid ways for the ball to return to player 11 after mm passes, modulo 998244353998244353.

2 1 0
0
3 3 0
2
7 13 5
1 3
4 5
5 4
6 1
2 2
443723615

Hint

For 10%10\% of the data, k=0k=0.

For another 15%15\% of the data, n500n\leq 500.

For another 20%20\% of the data, n5×104n\leq 5\times 10^4.

For another 20%20\% of the data, k300k\leq 300.

For 100%100\% of the data, 1n1091\leq n\leq 10^9, 0m2000\leq m\leq 200, 0kmin(n×(n1),5×104)0\leq k \leq \min(n\times(n-1),5\times 10^4), 1ai,bin1\leq a_i,b_i\leq n, it is not guaranteed that aia_i and bib_i are different.

Translated by ChatGPT 5