X. 航班路线检查

    Type: Default 1000ms 256MiB

航班路线检查

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目背景

翻译自 CSES-1682 题。

题目描述

nn 个城市和 mm 条航班连接。你的任务是检查是否可以通过现有的航班从任何一个城市到达任何其他城市。

输入格式

第一行包含两个整数 nnmm:分别表示城市的数量和道路的数量。城市编号为 1,2,,n1,2,…,n

接下来有 mm 行,每行包含两个整数 aabb:表示在城市 aa 和城市 bb 之间有一条单向航班。

输出格式

如果所有城市之间的路线都是可达的,输出 YES

如果存在不可达的城市对,输出 NO。同时输出两个城市 aabb,表示无法从城市 aa 到城市 bb。如果有多个解,输出任意一对城市。

样例

4 5
1 2
2 3
3 1
1 4
3 4
NO
4 2

说明/提示

1n1051 \leq n \leq 10^5

1m21051 \leq m \leq 2 \cdot 10^5

1a,bn1 \leq a, b \leq n

CSES4 图论

Not Claimed
Status
Done
Problem
36
Open Since
2025-5-21 0:00
Deadline
2025-5-31 23:59
Extension
24 hour(s)