QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#4504. 读书俱乐部

Statistics

波尔图读书俱乐部正为一年一度的图书交换活动而兴奋不已!每年,成员们都会带来他们最喜欢的书,并试图找到另一本他们喜欢的、且对方愿意交换的书。

我以前参加过这个图书交换活动,今年我绝对不想错过,但我认为交易方式应该改进。过去,对彼此的书感兴趣的成员只会进行简单的交换:想象一下,如果 A 带来了 B 喜欢的书,而 B 也带来了 A 喜欢的书,那么 A 和 B 就可以交换他们的书。

我后来意识到,许多成员最后还是带着他们带来的那本书回家了……如果我不寻找成对的交换,而是寻找三人组,我就能找到更多有效的交换!想象一下,成员 A 只喜欢成员 B 的书,而 B 只喜欢 C 的书,C 喜欢 A 的书。这 3 个人可以循环交换他们的书,每个人都会很高兴!

但为什么要止步于三人组呢?循环可以更大!你能帮我找出是否有可能让每个人都带着一本新书离开吗?请注意,成员们只有在收到他们喜欢的书时,才会交出自己的书。

题目描述

给定读书俱乐部的成员以及他们喜欢的书,我们能否找到循环,使得每个人都能收到一本新书?

输入格式

第一行包含两个整数:$N$(人数)和 $M$(“兴趣声明”的总数)。接下来的 $M$ 行,每行包含两个整数 $A$ 和 $B$,表示成员 $A$ 喜欢成员 $B$ 带来的书($0 \le A, B < N$)。数字 $A$ 和 $B$ 永远不会相同(成员从不通过喜欢自己带来的书来交换)。

输出格式

如果能为每位俱乐部成员找到一本新书,请输出 YES,否则输出 NO

数据范围

$2 \le N \le 10\,000$ $1 \le M \le 20\,000$ 且 $M \le N^2 - N$

样例

输入 1

9 9
0 1
1 2
2 0
3 4
4 3
5 6
6 7
7 8
8 5

输出 1

YES

位于波尔图市中心的莱罗书店的著名楼梯。

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.