Restaurant and dishes
As the World Cup season is on, every restaurant is either full or is on waiting.
A lot of people visit these restaurants in groups and like to watch the big World Cup matches.
An owner of a restaurant observed that some groups of people often ended up fighting over food.
The total budget that people have to spend on food is fixed so they order 'D' number of dishes that are the cheapest and they all eat by exchanging dishes.
If a person A liked B's dish and B liked A's dish, so they exchange it.
Let us consider another case, that is, if A liked B's dish ,B liked C's dish and C liked A's dish.
So they can exchange the dishes with each other to get what they like. These groups for exchanging dishes can have more than 3 members as well. But usually this sort of an exchange arrangement ends up in fight, as a number of people in the group do not get the dish they like and have to stick with the original dish they got.
The restaurant owner got a little worried because of the amount of fighting that has been going on in his restaurant everyday.
So, he need's some help to make a plan such that he got to know, in advance, that which group will fight. This will allow him to resolve
the matter immediately. Hence preventing the other groups from getting distracted and disturbed.
So Your task is to print 'yes' if it is possible to exchange dishes such that all become happy and if not possible then print 'no'.
Note: No person like the original dish they have.
The first line has two integers: N , the number of people, and D, the total number of
dishes they like.
The D lines that follow have two integers, A and B, indicating that member A likes the dish that member B got.
You should output YES if we can find a new dish for every person in the group and NO if that is
2 <= N <= 10000
1 <= D <=20000
0 <= A, B < N
Sample Test cases
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions