Logo
(追記) (追記ここまで)

10532번 - Book Club 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB178757148.299%

문제

Porto’s book club is buzzing with excitement for the annual book exchange event! Every year, members bring their favorite book and try to find another book they like that is owned by someone willing to trade with them.

I have been to this book exchange before, and I definitely do not want to miss it this year, but I feel that the trading should be improved. In the past, pairs of members interested in each other’s books would simply trade: imagine that person A brought a book that person B liked and vice-versa, then A and B would exchange their books.

I then realized that many members were left with the same book they walked-in with... If instead of looking for pairs I looked for triplets, I could find more valid exchanges! Imagine that member A only likes member B’s book, while B only likes C’s book and C likes A’s book. These 3 people could trade their books in a cycle and everyone would be happy!

But why stop at triplets? Cycles could be bigger and bigger! Could you help me find if it is possible for everyone to go out with a new book? Be careful, because members will not give their book without receiving one they like in return.

Given the members of the book club and the books they like, can we find cycles so that everyone receives a new book?

입력

The first line has two integers: N, the number of people, and M, the total number of “declarations of interest”. Each of the following M lines has two integers, A and B, indicating that member A likes the book that member B brought (0 ≤ A, B < N). Numbers A and B will never be the same (a member never likes the book he brought).

출력

You should output YES if we can find a new book for every club member and NO if that is not possible.

제한

  • 2 ≤ N ≤ 10 000
  • 1 ≤ M ≤ 20 000 and M ≤ N2 − N.

예제 입력 1

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

예제 출력 1

YES

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2014 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /