12901290 SUSTech Online Judge
Problem 1290 --Magic

1290: Magic

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 272  Solved: 51
[Submit][Status][Web Board]


Pisces is learning to build a magic field with a great magician. To build a magic field, Pisces must build some directed channels between \(N\) nodes to let the mana flow into it. Unfortunately, Pisces finds that these channels may have some circles, where the mana will get stuck in them forever! To maintain the stability of this magic field, Pisces wants to know whether it is possible to destroy at most one channel to make the magic field acyclic.


The first line contains an integer \(T\) \((1\leq T \leq 10)\), which denotes the number of test cases.

For each test case, the first line contains \(2\) integers \(n\) and \(m\) \((2 \leq n \leq 500, 1 \leq  m \leq min(n(n - 1), 100000))\) — the number of nodes and the number of channels, respectively. Each of the next \(m\) lines contains \(2\) integers \(u\) and \(v\) denoting a directed channel going from node \(u\) to node \(v\) \((1\leq u,v \leq  n,u \neq v)\). There is at most one directed channel from \(u\) to \(v\).


For each test case, print “Yes” (without quotes) if it’s possible, and “No” (without quotes) otherwise.

Sample Input

5 6
1 2
2 3
3 2
3 1
2 1
4 5

Sample Output