#P7845. 「dWoi R2」Change / 改造

「dWoi R2」Change / 改造

Description

After 9999 Replays, Saya finally realized that the maze is a directed acyclic graph.

To ensure the fun of the last Replay, Tokikaze Jun arranged a mini-game for Saya and Riki.

This directed acyclic graph GG has nn vertices and mm edges, and each edge has length 11. Let lil_i be the shortest path length from the starting vertex ss to the vertex uu pointed to by the ii-th edge. Define the weight of the ii-th edge as plip-l_i.

The game proceeds as follows (all choices are made in the order below, and everyone’s choices are public):

  1. Riki stands at vertex ss.
  2. Tokikaze Jun randomly selects a vertex as tt (tt may be equal to ss).
  3. If tt is not reachable from ss, the game ends immediately.
  4. Saya needs to choose an edge.
  5. Riki needs to find a path from ss to tt.
  6. If the edge chosen by Saya lies on the path chosen by Riki, then Riki will pay Saya the amount equal to the edge weight of that edge.

Riki wants to lose as little money as possible, while Saya wants to get as much money as possible. If both sides play optimally, what is the expected amount of money that Saya can obtain?

Input Format

The first line contains four integers n,m,s,pn,m,s,p, representing the number of vertices and edges of the directed graph, the vertex where Riki stands, and the pp appearing in the statement.

The next mm lines each contain two integers ui,viu_i,v_i, describing an edge.

Output Format

Output one integer on one line, representing the answer.

Please take the result modulo 998244353998244353.

8 8 1 10
1 2
1 3
1 4
2 5
3 5
5 6
6 7
6 8
6
3 2 1 3
1 2
1 3
332748119

Hint

Explanation of Sample 1

For example, when t=6t=6, Saya should choose the edge connecting 5,65,6; when t=8t=8, Saya should still choose the edge connecting 5,65,6; when t=4t=4, she should choose the edge connecting 1,41,4; when t=5t=5, no matter which edge Saya chooses, she will not get any money.

Let resures_u denote the maximum profit Saya can obtain when t=ut=u. Then we have res={0,9,9,9,0,7,7,7}res=\{0,9,9,9,0,7,7,7\}.

Explanation of Sample 2

Let resures_u denote the maximum profit Saya can obtain when t=ut=u. Then we have res={0,2,2}res=\{0,2,2\}.


Constraints and Notes

This problem uses bundled testdata.

  • Subtask 1 (10 pts): n,m5n,m \le 5.
  • Subtask 2 (20 pts): m=n1m=n-1, ui<viu_i<v_i, s=1s=1.
  • Subtask 3 (30 pts): n,m103n,m \le 10^3.
  • Subtask 4 (40 pts): no special restrictions.

For 100%100\% of the testdata, 1n,m5×1061 \le n,m \le 5 \times 10^6, 1sn1 \le s \le n, 1ui,vin1 \le u_i,v_i \le n, uiviu_i \ne v_i, np109n \le p \le 10^9.

Translated by ChatGPT 5