AdirectedgraphisasetV ofverticesandasetofE⊂V×V edges. An edge (u, v) is said to be directed from u to v (the edge (v, u) has the opposite direction). A directed cycle in a directed graph is a sequence of edges (u1,v1),(u2,v2),...,(uk,vk) such that ui+1 = vi for i = 1,...,k − 1, and u1 = vk. The directed cycle is simple if ui ̸= uj whenever i ̸= j (i.e., if it does not pass through a vertex twice). In a strongly connected directed graph, there is for every pair u, v of vertices some directed cycle (not necessarily simple) that visits both u and v. A directed graph is a cactus if and only if it is strongly connected and each edge is part of exactly one directed simple cycle. The first graph is a cactus, but the second one is not since for instance the edge (0,1) is in two simple cycles. The reason for the name is that a “cactus” consists of several simple cycles connected to each other in a tree-like fashion, making it look somewhat like a cactus. Write a program that given a directed graph determines if it is a cactus or not. The graph can have several thousand vertices. Input The first line contains an integer which is the number of test cases (less than 20). Each test case starts a line with an integer n > 0 followed by line with an integer m > 0 giving the number of vertices (n) and edges (m) in a graph (at most 10,000 of each). The vertices are numbered 0 through n − 1. The following m lines describe the edges as pairs of numbers u, v denoting an edge directed from u to v. There will never be more than one edge from u to v for any pair of vertices u and v. There are no loops, i.e., no edges from a vertex to itself. Output For each test case output a single line with a single string. Output ‘YES’ if the graph is a cactus, and output ‘NO’ if it is not.
2/2 Sample Input 2 4 5 01 12 20 23 32 4 5 01 12 23 30 13 Sample Output YES NO