CF1814F.Communication Towers

普及/提高-

通过率:0%

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.

输入格式

The first line contains two integers nn and mm ( 1n21051 \le n \le 2 \cdot 10^5 ; 0m41050 \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 ( 1liri21051 \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 ( 1vi,uin1 \le v_i, u_i \le n ; viuiv_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.

输出格式

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.

输入输出样例

  • 输入#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
首页