시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|

2 초 | 512 MB | 8 | 5 | 5 | 100.000% |

After finishing his studies, SpongeBob founded a company called Rahyab-Tech. Rahyab-Tech developed a mobile app called Rahyab, which helps drivers choose their path through inter-city roads. After a while, Rahyab became so popular that all drivers started using it during their trips.

SpongeBob discovered that one of the hardest problems he needs to solve is finding appropriate routes for drivers who want to go from Motel-Ghu to Tehran on Fridays. Every route starts with Motel-Ghu, and ends in Tehran after passing through some intermediate cities using the roads. Every road is a one-directional way from one city to another city. Roads do not have capacities. However, when more cars pass through a road, the road gets damaged faster. To avoid this, the government has the policy of charging every car by the most crowded road it has passed during its trip. The government’s surveillance system counts the number of cars passing through each road, and at the end of the day, each car is charged based on the roads it has passed. A car that passes through roads r_{1}, . . . , r_{k}, is charged max{t^{2}_{r1} , . . . , t^{2}_{rk} }, where t_{ri} is the number of cars passing through r_{i} during that day.

Rahyab’s suggested routes (from Motel-Ghu to Tehran) for different drivers are not necessarily the same. All drivers follow their suggested routes, but if any driver discovers somehow that (s)he could be charged less by using a route other than Rahyab’s suggestion, Rahyab loses its customer loyalty, something intolerable for SpongeBob. Thus, the route suggested to each driver should be one of the best possible routes for that driver.

SpongeBob has developed an intelligent program that at the start of a day, predicts the exact number of cars C that travel from Motel-Ghu to Tehran on that day. Now, he has hired you to improve Rahyab in a way that given the map of roads and the number C, its suggested routes to drivers are such that no driver could benefit from changing his/her route.

There are multiple test cases in the input. Each test case starts with a line containing five space-separated numbers N, E, M, T, and C. Integers N and E are respectively the number of cities and roads in the map (2 ≤ N ≤ 500, 0 ≤ E ≤ 100000). The cities are numbered 1 through N. Integers M and T are the number of Motel-Ghu and Tehran respectively (1 ≤ M, T ≤ N, M ≠ T). Integer C is the number of trips from Motel-Ghu to Tehran on Friday (0 ≤ C ≤ 10^{6} ). Each of the next E lines contains two space-separated integers x_{i} and y_{i} (1 ≤ x_{i} , y_{i} ≤ N) denoting a one-directional road from city x_{i} to city y_{i} . It is guaranteed that there is at least one route from Motel-Ghu to Tehran. The input terminates with a line containing 0 0 0 0 0 which should not be processed.

For each test case, print the total amount that all cars are charged if Rahyab’s routing plans meet the conditions mentioned above and are followed by all drivers. It is known that the total amount is unique.

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

91 54

ACM-ICPC > Regionals > Asia > Iran > Tehran Site 2016 J번