Under construction

Still being built. Things may change

Skeletons

Time limit2sMemory limit512 MB

Summary
For each directed graph, decide whether some positive real t lets every possible perfect matching of skeletons to targets be realized by walks of length exactly t.
Level

Hard8 of 10

Topics
Graph, Number theory, Math
Solved
No attempts yet

Problem

You just started your own clan in an online strategy game. Every clan owns several villages, and one-directional roads connect pairs of villages. The two ends of a road may be the same village. All roads have the same length. You can produce troops in your clan and then attack another clan. Your favorite troops are the wall breakers, skeletons that carry bombs, run, and blow up the walls of enemy villages. The skeletons are smart, and you cannot predict how they will move.

An attack goes like this. You pick the enemy clan, put one skeleton in every village of that clan, choose a positive real number tt for the bomb timers, and press the attack key. Every skeleton immediately picks one enemy village as its target, and the targets are picked so that every village is the target of exactly one skeleton. The starting village and the target village of a skeleton may be the same. During the attack all skeletons run at the same constant speed without stopping. They pass roads only in the allowed direction, and a skeleton may pass the same road several times. After exactly tt seconds every bomb goes off and all skeletons explode.

The attack succeeds if every skeleton explodes on its own target village. A skeleton is smart enough to pick a route that puts it on its target exactly tt seconds later whenever such a route exists. Given a list of clans, find the clans for which you can choose a timer value that makes the attack succeed no matter how the skeletons split the targets among themselves.

Input

The input holds the descriptions of several clans. The first line of each clan holds the number of villages nn and the number of roads mm (1≤n≤500001 \le n \le 50000, 1≤m≤1000001 \le m \le 100000). The villages are numbered 11 through nn. Each of the next mm lines holds two space separated integers xx and yy, a one-directional road from village xx to village yy. Several roads may connect the same two villages, and a road may start and end at the same village. The last line of the input is 0 0, and you do not process it.

Output

Print one line for each clan. Print Y if you can choose a timer value tt that guarantees the success of the attack, and N otherwise.

Examples2

  1. Example 1

    Input
    9 10
    1 2
    2 3
    3 4
    4 5
    5 1
    4 6
    6 7
    7 8
    8 9
    9 3
    3 3
    1 2
    2 3
    1 3
    0 0
    
    Expected output
    Y
    N
    
  2. Example 2

    Input
    2 2
    1 2
    2 1
    3 4
    1 2
    2 3
    3 1
    1 1
    0 0
    
    Expected output
    N
    Y