#P4575. [CQOI2013] 图的逆变换

[CQOI2013] 图的逆变换

Description

Given a directed graph DD with nn vertices and mm edges, construct a graph EE as follows: for each edge (u,v)(u,v) in DD, create a vertex uvuv in EE; then for any two edges (u,v)(u,v) and (v,w)(v,w) in DD, add a directed edge from uvuv to vwvw in EE. No other vertices or edges exist in EE.

Given EE, your task is to determine whether there exists a corresponding DD.

Note that DD may have parallel edges and self-loops.

Input Format

The first line contains the number of test cases TT (T10T\leq 10).

For each test case:

The first line contains an integer mm (0m3000\le m\le 300), the number of edges in DD (i.e., the number of vertices in EE).

The second line contains an integer kk, the number of edges in EE.

Each of the following kk lines contains two integers x,yx, y, indicating that there is a directed edge (x,y)(x,y) in EE. The vertices in EE are numbered from 00 to m1m-1.

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