#P4575. [CQOI2013] 图的逆变换
[CQOI2013] 图的逆变换
Description
Given a directed graph with vertices and edges, construct a graph as follows: for each edge in , create a vertex in ; then for any two edges and in , add a directed edge from to in . No other vertices or edges exist in .
Given , your task is to determine whether there exists a corresponding .
Note that may have parallel edges and self-loops.
Input Format
The first line contains the number of test cases ().
For each test case:
The first line contains an integer (), the number of edges in (i.e., the number of vertices in ).
The second line contains an integer , the number of edges in .
Each of the following lines contains two integers , indicating that there is a directed edge in . The vertices in are numbered from to .
Output Format
For each test case, output one line. If it exists, output Yes; otherwise, output No.
4
2
1
0 1
5
0
4
3
0 1
2 1
2 3
3
9
0 1
0 2
1 2
1 0
2 0
2 1
0 0
1 1
2 2
Yes
Yes
No
Yes
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号