问题 U: Tallest Cow

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:91 通过:26

题目描述

有 N 头牛站成一行,被编队为1、2、3…N,每头牛的身高都为整数。 

当且仅当两头牛中间的牛身高都比它们矮时,两头牛方可看到对方。

现在,我们只知道其中最高的牛是第 i 头,它的身高是 H ,剩余牛的身高未知。

但是,我们还知道这群牛之中存在着 M 对关系,每对关系都指明了某两头牛 A 和 B 可以相互看见。

求每头牛的身高的最大可能值是多少。

输入格式

第一行输入整数 N,i,H,M,数据用空格隔开。

接下来 M 行,每行输出两个整数 A 和 B ,代表牛 A 和牛 B 可以相互看见,数据用空格隔开。

输出格式

一共输出 N 行数据,每行输出一个整数。

第 i 行输出的整数代表第 i 头牛可能的最大身高。 



1≤N≤1000000,
1≤H≤1000000,
1≤A,B≤10000,
0≤M≤10000



FJ's N (1 ≤ N ≤ 10,00000) 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.

输入格式

Line 1: Four space-separated integers: N, I, H and R
Lines 2..R+1: Two distinct space-separated integers A and B (1 ≤ A, B ≤ N), indicating that cow A can see cow B.

输出格式

Lines 1..N: Line i contains the maximum possible height of cow i.


输入格式

第一行:四个以空格分隔的整数:n,i,h,Rn 和 R 意义见题面;i 和 h 表示第 i 头牛的高度为 h,他是最高的奶牛)

接下来 R 行:两个不同的整数 a 和 b1a,bn

输出格式

一共 n 行,表示每头奶牛的最大可能高度.

输入样例 复制

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

输出样例 复制

5
4
5
3
4
4
5
5
5

数据范围与提示

  • 此题中给出的关系对可能存在重复