#P5145. 漂浮的鸭子
漂浮的鸭子
Description
When it rains, puddles form on the ground. Each puddle flows to exactly one specific other puddle, and the flow is one-way (no backflow). Multiple puddles may flow into the same puddle. On this day, it started to rain "mixed with ducks", and there is a duck floating in every puddle. WYH dispatches an agent beside every puddle, and each agent marks the duck in his puddle. At a certain moment, all ducks start drifting along with the water simultaneously, and all agents start timing. When an agent sees the duck he marked drift back, he stops timing and reports the time to WYH. After surveying the terrain, WYH tells you the flow relation and travel time for every segment, and he wants to know the maximum among all the numbers he obtained.
Input Format
The first line contains a positive integer , meaning there are puddles (numbered from to ).
Lines each contain two positive integers. On line , the two integers are and , meaning the water of puddle flows to puddle , and the flow takes time . It is guaranteed that .
Output Format
Output a single integer, the maximum among the agent-reported times that WYH has.
6
2 1
3 2
1 3
5 2
6 2
4 2
6
Hint
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号