CF1814F.Communication Towers
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n communication towers, numbered from 1 to n, and m bidirectional wires between them. Each tower has a certain set of frequencies that it accepts, the i-th of them accepts frequencies from li to ri.
Let's say that a tower b is accessible from a tower a, if there exists a frequency x and a sequence of towers a=v1,v2,…,vk=b, where consecutive towers in the sequence are directly connected by a wire, and each of them accepts frequency x. Note that accessibility is not transitive, i. e if b is accessible from a and c is accessible from b, then c may not be accessible from a.
Your task is to determine the towers that are accessible from the 1-st tower.
共有 n 座通信塔,编号从 1 到 n,以及它们之间连接的 m 条双向通信线路。每座塔都支持某个频率范围:第 i 座塔支持的频率范围为 li 到 ri(含端点)。
我们称塔 b 可从塔 a 到达,当且仅当存在某个频率 x,以及一个塔序列 a=v1,v2,…,vk=b,使得该序列中相邻两座塔由一条线路直接相连,且序列中每一座塔均支持频率 x。注意:可达性不具备传递性,即若 b 可从 a 到达,且 c 可从 b 到达,这并不意味着 c 一定可从 a 到达。
你的任务是确定所有可从第 1 座塔到达的塔。
输入格式
The first line contains two integers n and m (1≤n≤2⋅105; 0≤m≤4⋅105) — the number of communication towers and the number of wires, respectively.
Then n lines follows, the i-th of them contains two integers li and ri (1≤li≤ri≤2⋅105) — the boundaries of the acceptable frequencies for the i-th tower.
Then m lines follows, the i-th of them contains two integers vi and ui (1≤vi,ui≤n; vi=ui) — the i-th wire that connects towers vi and ui. There are no two wires connecting the same pair of towers.
第一行包含两个整数 n 和 m(1≤n≤2⋅105;0≤m≤4⋅105),分别表示通信塔的数量和导线的数量。
接下来是 n 行,其中第 i 行包含两个整数 li 和 ri(1≤li≤ri≤2⋅105),表示第 i 座塔可接受的频率范围。
接下来是 m 行,其中第 i 行包含两个整数 vi 和 ui(1≤vi,ui≤n;vi=ui),表示连接第 vi 座塔与第 ui 座塔的第 i 条导线。不存在两条导线连接同一对塔。
输出格式
In a single line, print distinct integers from 1 to n in ascending order — the indices of the communication towers that are accessible from the 1-st tower.
在一行中,按升序输出 1 到 n 之间的互不相同的整数——即从第 1 座通信塔可达的通信塔的编号。
输入输出样例
输入#1
6 5 3 5 1 2 2 4 2 3 3 3 4 6 1 3 6 1 3 5 3 6 2 3
输出#1
1 3 5 6
输入#2
3 1 2 3 1 4 1 1 1 3
输出#2
1
输入#3
5 5 1 3 2 3 2 2 3 5 2 4 1 2 2 3 3 4 4 1 4 5
输出#3
1 2 3 4 5
输入解题思路,AI测评打分。不知道怎么写?