#P7845. 「dWoi R2」Change / 改造
「dWoi R2」Change / 改造
Description
After 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 has vertices and edges, and each edge has length . Let be the shortest path length from the starting vertex to the vertex pointed to by the -th edge. Define the weight of the -th edge as .
The game proceeds as follows (all choices are made in the order below, and everyone’s choices are public):
- Riki stands at vertex .
- Tokikaze Jun randomly selects a vertex as ( may be equal to ).
- If is not reachable from , the game ends immediately.
- Saya needs to choose an edge.
- Riki needs to find a path from to .
- 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 , representing the number of vertices and edges of the directed graph, the vertex where Riki stands, and the appearing in the statement.
The next lines each contain two integers , describing an edge.
Output Format
Output one integer on one line, representing the answer.
Please take the result modulo .
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 , Saya should choose the edge connecting ; when , Saya should still choose the edge connecting ; when , she should choose the edge connecting ; when , no matter which edge Saya chooses, she will not get any money.
Let denote the maximum profit Saya can obtain when . Then we have .
Explanation of Sample 2
Let denote the maximum profit Saya can obtain when . Then we have .
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (20 pts): , , .
- Subtask 3 (30 pts): .
- Subtask 4 (40 pts): no special restrictions.
For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号