#SFJSJJZN0X03D3. Tallest Cow
Tallest Cow
Description
FJ's cows conveniently indexed are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height of the tallest cow along with the index of that cow.
FJ has made a list of lines of the form "cow sees cow ". This means that cow is at least as tall as cow , and that every cow between and has a height that is strictly smaller than that of cow .
For each cow from , determine its maximum possible height, such that all of the information given is still correct. It is guaranteed that it is possible to satisfy all the constraints.
Input
Line : Four space-separated integers: Lines : Two distinct space-separated integers and , indicating that cow can see cow .
Output
Lines : Line contains the maximum possible height of cow .
Sample Input
9 3 5 5
1 3
5 3
4 3
3 7
9 8
Sample Output
5
4
5
3
4
4
5
5
5
Source
USACO 2007 January Silver
Limitation
2s, 64MiB for each test case.