Timing
Time limit1sMemory limit128 MB
Apply the directed fractional troop moves for t hours, then add each fortress value to its linked neighbors and report the minimum.
- Level
Medium4 of 10
- Topics
- Matrix, Simulation, Graph
- Solved
- No attempts yet
Problem
A collision between galaxies is coming. The galaxy ruled by MdI wants to annex ours by force. Our intelligence service broke into the enemy headquarters and came back with the whole troop movement plan.
The enemy troops are spread over fortresses. Let be the power statistic of the troops in fortress . The plan moves troops along links. A link means that every hour a fraction of the troops in fortress crosses over to fortress . The travel time between fortresses is ignored.
All moves inside one hour happen at the same time and use the values from the start of that hour, so after one hour fortress holds
The government picked the hour at which the attack starts, so the enemy follows the plan for hours. The enemy galaxy is far away and our fleet needs one hour to get there. MdI notices the target the moment the fleet leaves and immediately moves every soldier who can reach it. Direction stops mattering during that hour, so a fortress joined to the target fortress by a link sends all of its troops to and keeps none.
The power statistic gathered at fortress when the fleet arrives is therefore after hours plus the value of every fortress joined to by a link. Writing for the set of fortresses joined to by at least one link, with itself left out,
Link direction is ignored here, and a fortress counts once even when several links join it to .
Find the weakest point of the enemy galaxy, that is the smallest over all fortresses.
Input
The first line has the number of test cases ().
The first line of each test case has the number of enemy fortresses (), the number of links (), and the hour of the attack (). The second line has real numbers (), where is the power statistic of the troops in fortress .
Each of the next lines describes one link with an integer (), an integer (), and a real number (), meaning that every hour a fraction of the troops in fortress moves to fortress . The same pair may appear more than once, and a link with is possible. The ratios on the links leaving one fortress add up to at most 1.
Output
For each test case print, on its own line, the value of the weakest point of the enemy galaxy, that is the smallest power statistic that can gather in a single fortress by the time the fleet arrives.
Round the value at the seventh digit after the decimal point and print exactly six digits after the decimal point. If the answer is , print 305.000000. Every input keeps the answer far away from a rounding boundary, so the rounding direction is never in doubt.
Hint
Every link works both ways at the moment the attack starts. A fortress joined to the target by a link sends all of its troops there, whichever way the link points.
The moves during the hours before that follow the plan and keep their direction. Only the last hour ignores it.