One day, Koraidon gave Miraidon a directed graph with vertices and
edges. The weights of all edges are
. Koraidon asked Miraidon to calculate the shortest path from vertex
to each vertex. It is guaranteed that vertex
can reach all other vertices through the edges.
However, Miraidon just forgot the BFS algorithm. He tried to use the DFS algorithm as a replacement. The algorithm looks like:
In line , Miraidon tried to use a random shuffle function to get a correct answer. The shuffles in different recursive calls of DFS are mutually independent.
Koraidon judged the answer given by Miraidon very strictly. He would consider the algorithm correct if and only if the algorithm gives correct answers on all possible random shuffle results.
Each test contains multiple test cases.
The first line contains an integer
(
) – the number of test cases.
For each test case:
The first line contains two integers
(
).
Each of the next
lines contains two integers
and
(
), denoting a directed edge from
to
. The graph is not guaranteed to be a simple directed graph. But it is guaranteed that vertex
can reach all other vertices through the edges.
It is guaranteed that the sum of
and the sum of
over all test cases do not exceed
.
For each test case, print “Yes” if the algorithm is correct on this graph, and “No” otherwise.
You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.
For the first example, there is only one possible DFS order, which isFor the second example, consider the following DFS order:. The distance from vertex
to vertex
are
, respectively. They are exactly the shortest paths. So the algorithm is correct on this graph.
. The distance of vertex
is
, while the shortest path has length
(
). So the algorithm is wrong on this graph.