Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
2.00/5 (5 votes)
See more:
Have you ever thought, when given an undirected graph in some problem, that it would be easier to solve it if the graph's edges were actually its vertices and the graph's vertices were its edges? This problem is right about this -- unfortunately, not about bears and bees (but if you want, you may think of vertices as of bears and of edges as of bees (or even vice versa)).

Suppose you're given an undirected graph G0 with N vertices and M edges. Let's perform a simple transformation on graph G0 to obtain graph G1 with M vertices so that each vertex of G1 corresponds to a unique edge of G0 and a pair of vertices in G1 is connected by a single edge if and only if the corresponding edges of G0 share a common vertex. Similarly, let's perform a simple transformation on graph G1 to obtain graph G2, and let's perform a simple transformation on graph G2 to obtain graph G3.

All you have to do is to output the number of vertices and edges in G3.

Input

The first line of the input file contains one integer T -- the number of test cases (no more than 10). Each test case is described by a line containing two integers N and M (1 ≤ N, M ≤ 1000) followed by M lines, each containing two integers between 1 and N, inclusive, separated by a single space and describing an edge of graph G0. It's guaranteed that each edge connects two distinct vertices and each pair of vertices is directly connected by at most one edge.

Output

For each test case output just one line containing two integers -- the number of vertices and edges in G3.

Explanation:

In the first test case the given graph is a "triangle". It's easy to see that a simple transformation on a triangle results in the same triangle (as it contains three pairwise connected vertices and three pairwise "connected" edges).
Posted
Comments
Tim Corey 2-Jun-12 14:26pm    
Do you have a question about something in this information? It looks like you are posting a homework question that has been translated via Google translate into English. This forum isn't for doing challenges, it is for answering real-world questions that people are struggling with.
Stefan_Lang 4-Jun-12 8:59am    
Your introduction may be misleading. The transformation you describe is not bidirectional, i. e. you can not always reverse it. That means the transformation looses information and therefore any algorithm performed on the transformed graph may not provide any insight on how to solve a particular problem of the original graph.

Example:
G0 = {V0, E0}; V0 = {1, 2, 3, 4}; E0 = {a(1,4), b(2, 4), c(3,4)} (a three-pod)
G1 = {V1, E1}; V1 = {a, b, c}, E1 = (I(a, b), II(b, c), III(c, a)} (a triangle)

The vertex 4 in G0 has 3 edges, and therefore is not represented in G1, nor can it be reconstructed from G1.

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
[no name] 3-Jun-12 6:11am    
I have solved this myself i just ask it for fun ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900