问题 D: Koraidon, Miraidon and DFS Shortest Path

内存限制:1024 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:5 通过:3

题目描述


One day, Koraidon gave Miraidon a directed graph with nnn vertices and mmm edges. The weights of all edges are 111. Koraidon asked Miraidon to calculate the shortest path from vertex 111 to each vertex. It is guaranteed that vertex 111 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 444, 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.
Please help Miraidon check whether his DFS algorithm is correct on the given graph.

输入格式


Each test contains multiple test cases.
The first line contains an integer TTT (1≤T≤5×1051\leq T\leq 5\times10^{5}1T5×105) – the number of test cases.
For each test case:
The first line contains two integers n,mn,mn,m (1≤n,m≤5×1051\leq n,m\leq 5\times 10^51n,m5×105).
Each of the next mmm lines contains two integers uuu and vvv (1≤u,v≤n1\le u,v\le n1u,vn), denoting a directed edge from uuu to vvv. The graph is not guaranteed to be a simple directed graph. But it is guaranteed that vertex 111 can reach all other vertices through the edges.
It is guaranteed that the sum of nnn and the sum of mmm over all test cases do not exceed 5×1055\times10^{5}5×105.

输出格式


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.

输入样例 复制

2
3 3
1 2
2 3
3 1
3 3
1 2
1 3
2 3

输出样例 复制

Yes
No