Bucket Game
InterviewTime limit2sMemory limit1024 MB
Water poured into bucket 1 splits equally among each bucket's outgoing hoses in a DAG. Find the largest amount any single bucket holds.
- Level
Easy3 of 10
- Topics
- Graph, Topological sort, Dynamic programming
- Solved
- No attempts yet
Problem
Chanwoo agreed to play a simple game with participants of the Cheonha Jeil Coding Contest. The game is called 'Bucket Game'. Pour units of water into the top bucket and let it flow. The winner picks the bucket that ends up holding the most water. Chanwoo cannot see how the buckets are connected until he picks one, but he already knows how they are connected. Find how much water is in the bucket Chanwoo must pick to win.
Bucket is always at the top. When a bucket holding unit of water has outgoing hoses, water flows through each hose at per hose until the bucket is empty. A smaller bucket number means a higher position, so water always flows from a smaller-numbered bucket to a larger-numbered one.
Input
The first line has the number of buckets and the number of hoses , separated by a space. (, )
Each of the next lines has two integers and , separated by a space. () This means a hose carries water from bucket to bucket .
No hose is given more than once. That is, every pair in the input is different.
Output
Pour units of water into bucket and let it flow. Print the largest amount of water held by any single bucket. The answer is accepted if its absolute or relative error from the true answer is at most .
Hint
Absolute error is the difference between the true answer and the printed value. Relative error is the absolute error divided by the true answer. If the true answer is and the printed value is , the absolute error is and the relative error is .