|
||||||||||
Graph¡¯s Cycle ComponentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 2585 Accepted Submission(s): 980 Problem Description In graph theory, a cycle graph is an undirected graph that consists of a single cycle, or in other words, some number of vertices connected in a closed chain. Now, you are given a graph where some vertices are connected to be components, can you figure out how many components are there in the graph and how many of those components are cycle graphs. Two vertices belong to a same component if and only if those two vertices connect each other directly or indirectly. Input The input consists of multiply test cases. The first line of each test case contains two integer, n (0 < n < 100000), m (0 <= m <= 300000), which are the number of vertices and the number of edges. The next m lines, each line consists of two integers, u, v, which means there is an edge between u and v. You can assume that there is no multiply edges and no loops. The last test case is followed by two zeros, which means the end of input. Output For each test case, output the number of all the components and the number of components which are cycle graphs. Sample Input
Sample Output
Author momodi@WHU Source | ||||||||||
|