QOJ.ac

QOJ

시간 제한: 1.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#17892. 律师们

통계

$N$ 名律师因涉嫌欺诈罪被起诉。这 $N$ 名律师试图通过互相辩护来确保所有人都能无罪释放。

只有当律师 $B$ 信任律师 $A$ 时,律师 $A$ 才能为律师 $B$ 辩护。这样的关系对 $(A, B)$ 共有 $M$ 个。(这并不意味着律师 $A$ 信任律师 $B$)。

由于每位律师的业务能力都非常出色,任何人只要获得至少一人的辩护,就无条件被宣告无罪。

但是,如果律师 $A$ 为律师 $B$ 辩护,且律师 $B$ 也为律师 $A$ 辩护,这看起来会非常可疑,导致两人都会被判有罪。

对于每个关系对 $(A, B)$,你可以选择律师 $A$ 是否为律师 $B$ 辩护。请判断是否存在一种选择方案,使得所有律师都能无罪释放。

输入格式

第一行包含两个整数 $N$ 和 $M$,分别表示律师的人数和信任关系的数量($1 \le N, M \le 200,000$)。

接下来的 $M$ 行,每行包含两个整数 $A_i$ 和 $B_i$($1 \le A_i, B_i \le N$,$A_i \neq B_i$),表示律师 $B_i$ 信任律师 $A_i$(即律师 $A_i$ 可以为律师 $B_i$ 辩护)。

保证不存在 $1 \le i \neq j \le M$ 使得 $A_i = A_j$ 且 $B_i = B_j$(即不会出现重复的有序对)。

输出格式

如果可以使所有律师都获得至少一人的辩护,且不存在互相辩护的律师对,则输出 YES。否则,输出 NO

样例

输入 1

3 3
1 2
2 3
3 1

输出 1

YES

输入 2

4 6
1 2
1 3
1 4
2 3
2 4
3 4

输出 2

NO

输入 3

4 4
1 2
2 1
3 4
4 3

输出 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.