• محدودیت زمان: ۶ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

After finishing his studies, SpongeBob founded a company called Rahyab-Tech. Rahyab-Tech eveloped 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 r1,,rkr_1, \dots , r_k, is charged tr12,,ttk2{t_{r_1}^2, \dots, t_{t_k}^2} where trit_{r_i} is the number of cars passing through rir_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 CC 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 CC, 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 NN, EE, MM, TT, and CC. Integers NN and EE are respectively the number of cities and roads in the map (2N5002 \leq N \leq 500, 0E100,0000 \leq E \leq 100,000). The cities are numbered 11 through NN. Integers MM and TT are the number of Motel-Ghu and Tehran respectively (1MTN1 \leq M \neq T \leq N). Integer CC is the number of trips from Motel-Ghu to Tehran on Friday (0C1060 \leq C \leq 10^6). Each of the next EE lines contains two space-separated integers xix_i and yiy_i (1xi,yiN1 \leq x_i , y_i \leq N) denoting a one-directional road from city xix_i to city yiy_i. It is guaranteed that there is at least one route from Motel-Ghu to Tehran. The input terminates with a line containing 00 00 00 00 00 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
Plain text

خروجی نمونه ۱

91
54
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.