Tallest Cow
Description
FJ's \(N (1 \le n \le 10^4)\) cows conveniently indexed \(1\) to \(n\) are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height \(h (1 \le h \le 10^6)\) of the tallest cow along with the index \(p\) of that cow.
FJ has made a list of \(m (0 \le m \le 10^4)\) lines of the form "cow \(17\) sees cow \(34\)". This means that cow \(34\) is at least as tall as cow \(17\), and that every cow between \(17\) and \(34\) has a height that is strictly smaller than that of cow \(17\).
For each cow from \(1\) to \(n\), 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 1: Four space-separated integers: \(n, p, h, m\)
Lines \(2\) to \(m+1\): Two distinct space-separated integers \(a\) and \(b\) \((1 \le a, b \le n)\), indicating that cow \(a\) can see cow \(b\).
Output
Lines \(1\) to \(n\): Line \(i\) contains the maximum possible height of cow \(i\).
Simplified
给出 \(n\) 头牛的身高,和 \(m\) 对关系(\(a_i\) 与 \(b_i\) 可以相互看见。即他们中间的牛都比他们矮)。已知最高的牛为第 \(p\) 头,身高为 \(h\)。
求每头牛的身高最大可能是多少。
Samples
Sample #1
Input
9 3 5 5
1 3
5 3
4 3
3 7
9 8
Output
5
4
5
3
4
4
5
5
5
Source
算法竞赛进阶指南 POJ
信息
- ID
- 1011
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 3
- 已通过
- 2
- 通过率
- 67%
- 上传者