CF1814F.Communication Towers

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn communication towers, numbered from 11 to nn, and mm bidirectional wires between them. Each tower has a certain set of frequencies that it accepts, the ii-th of them accepts frequencies from lil_i to rir_i.

Let's say that a tower bb is accessible from a tower aa, if there exists a frequency xx and a sequence of towers a=v1,v2,…,vk=ba=v_1, v_2, \dots, v_k=b, where consecutive towers in the sequence are directly connected by a wire, and each of them accepts frequency xx. Note that accessibility is not transitive, i. e if bb is accessible from aa and cc is accessible from bb, then cc may not be accessible from aa.

Your task is to determine the towers that are accessible from the 11-st tower.

共有 nn 座通信塔,编号从 11 到 nn,以及它们之间连接的 mm 条双向通信线路。每座塔都支持某个频率范围:第 ii 座塔支持的频率范围为 lil_i 到 rir_i(含端点)。

我们称塔 bb 可从塔 aa 到达,当且仅当存在某个频率 xx,以及一个塔序列 a=v1,v2,…,vk=ba = v_1, v_2, \dots, v_k = b,使得该序列中相邻两座塔由一条线路直接相连,且序列中每一座塔均支持频率 xx。注意:可达性不具备传递性,即若 bb 可从 aa 到达,且 cc 可从 bb 到达,这并不意味着 cc 一定可从 aa 到达。

你的任务是确定所有可从第 11 座塔到达的塔。

输入格式

The first line contains two integers nn and mm (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 0≤m≤4⋅1050 \le m \le 4 \cdot 10^5) — the number of communication towers and the number of wires, respectively.

Then nn lines follows, the ii-th of them contains two integers lil_i and rir_i (1≤li≤ri≤2⋅1051 \le l_i \le r_i \le 2 \cdot 10^5) — the boundaries of the acceptable frequencies for the ii-th tower.

Then mm lines follows, the ii-th of them contains two integers viv_i and uiu_i (1≤vi,ui≤n1 \le v_i, u_i \le n; vi≠uiv_i \ne u_i) — the ii-th wire that connects towers viv_i and uiu_i. There are no two wires connecting the same pair of towers.

第一行包含两个整数 nn 和 mm(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;0≤m≤4⋅1050 \le m \le 4 \cdot 10^5),分别表示通信塔的数量和导线的数量。

接下来是 nn 行,其中第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤2⋅1051 \le l_i \le r_i \le 2 \cdot 10^5),表示第 ii 座塔可接受的频率范围。

接下来是 mm 行,其中第 ii 行包含两个整数 viv_i 和 uiu_i(1≤vi,ui≤n1 \le v_i, u_i \le n;vi≠uiv_i \ne u_i),表示连接第 viv_i 座塔与第 uiu_i 座塔的第 ii 条导线。不存在两条导线连接同一对塔。

输出格式

In a single line, print distinct integers from 11 to nn in ascending order — the indices of the communication towers that are accessible from the 11-st tower.

在一行中,按升序输出 11 到 nn 之间的互不相同的整数——即从第 11 座通信塔可达的通信塔的编号。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页