eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

Flood

We all know that King Triton doesn’t like us and therefore shipwrecks, hurricanes and tsunami do happen. But being bored with the same routine all these years Triton has decided to make a spectacular flood this year. He chose a small town in a hilly valley not far from the sea. The power of Triton is enough to pour one heavy rain on the hill. He is worried however that water will miss that chosen town due to various river basins and water flows. Triton asks you to help him help calculate the amount of water that reaches the chosen town. There are water ponds in a hilly valley on the way to the town. Some of them are connected to each other with rivers. If some pond is overfull with water, the water begins to flow evenly to the connected ponds (or to the sea, if there are no connected ponds). Each pond contains some water initially, and the maximum pond capacity is also known. The chosen town is located on the bank of one pond --- you should calculate the water level in this pond after all water flow is run out. \InputFile On the first line of input integers \textbf{N} and \textbf{K} (\textbf{2} ≤ \textbf{N} ≤ \textbf{10^4}, \textbf{0} ≤ \textbf{K} ≤ \textbf{10^5}) are given --- the number of water ponds and the number of pond connections respectively. On the next \textbf{N} lines of input integers \textbf{P_i} and \textbf{A_i} (\textbf{0} ≤ \textbf{A_i} ≤ \textbf{P_i} ≤ \textbf{10^6}) are given --- these are the maximum ith water pond capacity and its initial water level. On the next \textbf{K} lines of input integers \textbf{F_j} and \textbf{T_j} (\textbf{1} ≤ \textbf{F_j}, \textbf{T_j} ≤ \textbf{N}, \textbf{F_j} ≠ \textbf{T_j}) are given --- they denote a possible river flow connection from \textbf{F_j} to \textbf{T_j} water pond (reverse water flow is not possible). Consider water flow from a pond to be equally distributed between all possible flow connections from that pond. Triton is absolutely sure that there are no cycles in river flows between the ponds, and there are no multiple rivers between any two ponds. On the last line of input integers \textbf{X}, \textbf{Y} and \textbf{Z} (\textbf{1} ≤ \textbf{X}, \textbf{Z} ≤ \textbf{N}, \textbf{1} ≤ \textbf{Y} ≤ \textbf{10^6}) are given --- the water pond that receives Triton’s heavy rain, the amount of water that is added to this pond and the target pond (near the chosen town) to test respectively. Consider that excessive water flows from a water pond if and only if its capacity is full. If some pond is overfull and no water flows are defined from that pond consider that all excessive water has flown out to the sea. \OutputFile The first line of the output should contain a single floating-point number \textbf{L_z} --- the final water level in the target pond when all water flow is complete. Answers with absolute or relative error less than \textbf{10^\{-4\}} are considered correct.
Лимит времени 1 секунда
Лимит использования памяти 256 MiB
Входные данные #1
4 4
10 10
1 0
1 0
10 0
1 2
1 3
2 4
3 4
1 5 4
Выходные данные #1
3.0
Источник ACM ICPC 2012-2013, NEERC, Moscow Subregion, Moscow, Sunday, October 21, 2012