#1817. 合法与否

合法与否

题目描述

小青遇到了这样一个问题:ACM-DIY is a large QQ group where many excellent acmers get together. Every day many holy cows chat on-line to exchange their ideas. When someone has questions, many warm-hearted cows like Lost will come to help. Then the one being helped will call Lost master, and Lost will have a nice prentice. But then problem occurs: there are too many masters and too many prentices, how can we know whether it is legal or not? Please note that the master and prentice relation is transitive.

输入格式

The input consists of several test cases. For each case, the first line contains two integers, N (members to be tested) and M (relationships to be tested) (2 <= N, M <= 100). Then M lines follow, each contains a pair of (x, y) which means x is y's master. The input is terminated by N = 0.

输出格式

For each test case, print in one line the judgement of the messy relationship. If it is legal, output YES, otherwise NO.

样例

样例 1

输入 # 1

4 3
0 1
1 2
2 3
3 3
0 1
1 2
2 0
0 1

输出 # 1

YES
NO