#P6835. [Cnoi2020] 线形生物

    ID: 6171 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2020O2优化期望洛谷月赛

[Cnoi2020] 线形生物

Background

In order to live happily in the Underworld rather than being sentenced to hell, humans have abandoned the practice of ending their own lives and are doing their best to live. From this perspective, humans seem somewhat positive and lovable. (Shameimaru Aya)

Linear creatures move one-way toward the Underworld along a one-dimensional staircase.

In that case, it only needs to climb step by step for nn steps to reach Hakugyokurou.

But Cirno felt this was too monotonous, so the one-dimensional barrier was broken, and the chain-like road grew cauliflower-like branches.

Problem Description

A linear creature needs to walk from step 11 to step n+1n+1.

At the beginning, for steps 1,2,3,,n1,2,3,\ldots,n, each step has a directed edge to the next step ii+1i\rightarrow i+1.

Then Cirno adds mm atavistic edges uivi(uivi)u_i \rightarrow v_i (u_i \ge v_i), which form an atavistic graph.

At each step, the linear creature will choose uniformly at random one outgoing edge from the current step and move to the corresponding step.

When it reaches step n+1n+1, it stops walking.

Meanwhile, Cirno counts the total number of steps the linear creature takes, denoted by δ\delta.

Cirno wants to know the value of E(δ)E(\delta) (i.e. the mathematical expectation of δ\delta) modulo 998244353998244353.

Input Format

The first line contains three integers idid, nn, and mm.

The next mm lines each contain two integers uiu_i and viv_i.

idid indicates the subtask ID. The meanings of the other letters are the same as above.

Output Format

One line with one integer: E(δ)E(\delta). The meanings of the letters are the same as above.

1 5 5
1 1
2 2
3 3
4 4
5 5
10
2 5 5
1 1
2 1
3 2
4 3
5 4
30
3 5 5
1 1
2 1
3 1
4 1
5 1
62
4 5 5
1 1
3 1
4 2
5 1
5 5
35

Hint

Required Mathematical Knowledge

  • Power series summation that may be used: If x>1x>1, then $\sum\limits_{i=1}^{\infty}\big(\frac{1}{x}\big)^i=\frac{1}{x}+\frac{1}{x^2}+\frac{1}{x^3}+\cdots=\frac{1}{x-1}$.
  • Mathematical expectation: In a random experiment, the sum of the probability of each possible outcome multiplied by its outcome, reflecting the average value of a random variable.
  • Discrete expectation formula: E(x)=k=1xkpkE(x)=\sum\limits_{k=1}^{\infty}x_kp_k.

Constraints and Conventions

For 100%100\% of the testdata, it is guaranteed that id{1,2,3,4,5}id \in \{1,2,3,4,5\}, 0<n,m1060 < n,m \le 10^6, and 1viuin1 \le v_i \le u_i \le n.

Subtasks (This problem uses bundled evaluation)

  • Subtask1 (10%10\%): In the atavistic graph, every node has a self-loop and all edges are self-loops (not drawn). The whole graph looks like:

  • Subtask2 (10%10\%): In the atavistic graph, every node has an edge to and only to its predecessor. In particular, the predecessor of node 11 is node 11. The whole graph looks like:

  • Subtask3 (10%10\%): In the atavistic graph, every node has an edge to and only to node 11. The whole graph looks like:

  • Subtask4 (10%10\%): n100n \le 100, m1000m \le 1000.

  • Subtask5 (60%60\%): No special restrictions.

Postscript

The problem name comes from Touhou Kikeijuu (th17), Stage 6 Boss Keiki Haniyasushin, Hard / Lunatic difficulty spell card: 線形「リニアクリーチャー」.

Translated by ChatGPT 5