#P1685. 游览
游览
Description
After you have successfully passed Huang Yaoshi (Huang Yaoshi)ʼs test, you can now freely tour Peach Blossom Island.
You start from the west end of the island and travel all the way to the east end, then leave from the pier at the east end. After one tour, you find the scenery of Peach Blossom Island so beautiful that you want to take a boat from the east pier back to the west end and tour again. However, there is a rule: you may tour any number of times, but the route taken each time cannot be exactly the same.
We model the island as a directed graph with vertices representing intersections and directed edges representing roads. Multiple edges between the same ordered pair of vertices may exist. The input guarantees that the graph has no cycles, and that there is at least one route from the west end to the east end. Two routes are considered different if and only if the exact sequence of edges they traverse is not identical.
Your task: How much total time does it take to finish touring all different routes? Between two consecutive tours, you take the boat from the east end back to the west end once, which costs time. After the last tour, you leave from the east pier and do not return.
Input Format
The first line contains integers , representing the number of vertices, the number of edges, the index of the west end, the index of the east end (indices are from to ), and the time to take the boat once from the east end back to the west end.
Each of the following lines contains integers , indicating that there is a directed edge from vertex to vertex with travel time .
Numbers on each line are separated by a single space.
Output Format
Assume the total time is . Output the value of ( modulo ).
3 4 1 3 7
1 2 5
2 3 7
2 3 10
1 3 15
56
Hint
[Sample Explanation]
There are routes from vertex to vertex , namely , , and .
Time calculation: .
Constraints
, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号