This page is still under construction.

Parts of this page are still being built. What you see may change.

Cube of a Graph

Time limit1sMemory limit128 MB

Summary
Count vertices, adjacent pairs, and triangles whose incident edges are all nontrivial bridges in a connected graph.
Level

Medium6 of 10

Topics
Graph, DFS, Brute force
Solved
No attempts yet

Problem

The cube G3G^3 of a graph G=(V,E)G = (V, E) is the graph on the vertex set VV in which two vertices are joined by an edge whenever their distance in GG is at most three. The distance between two vertices is the number of edges on a shortest path connecting them.

A bridge (also called a cut-edge) is an edge whose deletion increases the number of connected components. Equivalently, an edge is a bridge if and only if it lies on no cycle. The degree of a vertex is the number of edges incident to it, and a bridge is nontrivial when neither of its two endpoints has degree one.

Building on these ideas, three notions are defined.

  • A vertex is a pure bridge vertex if every edge incident to it is a nontrivial bridge.
  • Three distinct, mutually adjacent vertices, each of degree at least three, form a pure bridge triangle if every edge of GG that is incident to exactly one of the three vertices is a nontrivial bridge.
  • Two adjacent vertices form a pure bridge pair if both of them are pure bridge vertices.

Figure 1. A connected graph with seven nontrivial bridges, drawn as dotted lines. It has three pure bridge vertices 7, 8, and 15, one pure bridge triangle {9,10,14}\{9, 10, 14\}, and one pure bridge pair {7,8}\{7, 8\}.

It is known that the cube of any connected graph is Hamiltonian-connected: every two vertices of G3G^3 are joined by a Hamiltonian path.

Given a connected graph, count all of its pure bridge vertices, pure bridge triangles, and pure bridge pairs.

Input

The first line contains the number of test cases TT. Each test case follows.

The first line of a test case contains two integers nn and mm: the number of vertices and the number of edges of a graph GG, where n≤3000n \le 3000 and m≤1,000,000m \le 1{,}000{,}000. Each of the next mm lines contains two integers uu and vv, describing an edge between vertices uu and vv. The graph is connected and its vertex set is {1,2,…,n}\{1, 2, \dots, n\}.

Output

For each test case, print one line with three integers separated by single spaces: the number of pure bridge vertices, the number of pure bridge triangles, and the number of pure bridge pairs, in that order.

Examples5

  1. Example 1

    Input
    2
    5 4
    2 3
    1 2
    3 4
    5 4
    17 20
    1 2
    2 3
    3 4
    4 1
    2 4
    4 7
    5 6
    6 7
    7 8
    8 9
    9 10
    10 14
    14 9
    10 11
    11 12
    12 13
    13 11
    14 15
    15 16
    16 17
    
    Expected output
    1 0 0
    3 1 1
    
  2. Example 2

    Input
    1
    7 6
    1 2
    1 3
    1 4
    2 5
    3 6
    4 7
    
    Expected output
    1 0 0
    
  3. Example 3

    Input
    1
    6 5
    1 2
    1 3
    2 4
    3 5
    4 6
    
    Expected output
    2 0 1
    
  4. Example 4

    Input
    1
    9 9
    1 2
    2 3
    3 1
    1 4
    2 5
    3 6
    4 7
    5 8
    6 9
    
    Expected output
    0 1 0
    
  5. Example 5

    Input
    1
    14 15
    1 2
    2 3
    3 1
    4 5
    5 6
    6 4
    3 4
    1 7
    2 8
    5 9
    6 10
    7 11
    8 12
    9 13
    10 14
    
    Expected output
    0 2 0