第32906题 程序题
[Usaco2007 Jan]Tallest Cow 最高的牛

原题描述(英文)

FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..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 ≤ H ≤ 1,000,000) of the tallest cow along with the index I of that cow. FJ has made a list of R (0 ≤ R ≤ 10,000) 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..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.

题目描述(中文)

FJ 的 N (1 ≤ N ≤ 10,000) 头牛按 1~N 编号排成一列,每头牛的高度为正整数。已知最高的牛高度为 H (1 ≤ H ≤ 1,000,000),编号为 I。 FJ 给出了 R (0 ≤ R ≤ 10,000) 条关系,格式为「牛 A 能看到牛 B」,含义是:牛 B 的高度至少和牛 A 一样高,且 A 和 B 之间的所有牛的高度都严格小于牛 A 的高度。 要求在满足所有约束的前提下,求出每头牛的最大可能高度,题目保证存在合法解。

输入描述

  • 第一行:四个空格分隔的整数 N、I、H、R
  • 第 2 到 R+1 行:每行两个不同的整数 A 和 B (1 ≤ A,B ≤ N),表示牛 A 能看到牛 B

输出描述

  • 共 N 行,第 i 行输出第 i 头牛的最大可能高度

输入样例

9 3 5 5
1 3
5 3
4 3
3 7
9 8

输出样例

5
4
5
3
4
4
5
5
5

提示

输入说明:共 9 头牛,第 3 头是最高的,高度为 5。

编辑模式
程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析