QOJ.ac

QOJ

時間限制: 6 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#14229. 天空之岛

统计

一个简单的空岛

Alex 想要建造一个由 $N$ 个空岛组成的空中基地,空岛编号为 $1, \dots, N$。一共有 $M$ 座桥,直接连接某些空岛。因为她没有鞘翅(能让玩家飞行的翅膀)且无法飞行,所以她需要确保存在一种方法可以让她从任意一个空岛前往其他任意一个空岛。如果需要途径其他空岛才能到达目的地也是可以的。如果满足这一性质,我们称她的空岛是连通的。注意:单个空岛总是连通的。

给定空岛的数量 $N$ 以及所有的桥 $b_1, \dots, b_M$,你能否判断 Alex 的空岛是否连通?

输入格式

输入的第一行包含两个空格分隔的整数 $1 \le N \le 900$ 和 $0 \le M \le 10^6$,分别表示空岛的数量和桥的数量。

接下来的 $M$ 行,每行包含两个空格分隔的整数 $1 \le a, b \le N$,表示空岛 $a$ 和空岛 $b$ 之间有一座桥。

输出格式

如果 Alex 的所有空岛都是连通的,输出 YES。否则,输出 NO

样例

输入样例 1

4 3
1 2
2 3
3 4

输出样例 1

YES

输入样例 2

4 4
1 2
2 3
3 4
4 1

输出样例 2

YES

输入样例 3

4 3
1 2
2 1
3 4

输出样例 3

NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.