Cube of a Graph
Time limit1sMemory limit128 MB
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 of a graph is the graph on the vertex set in which two vertices are joined by an edge whenever their distance in 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 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 , and one pure bridge pair .
It is known that the cube of any connected graph is Hamiltonian-connected: every two vertices of 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 . Each test case follows.
The first line of a test case contains two integers and : the number of vertices and the number of edges of a graph , where and . Each of the next lines contains two integers and , describing an edge between vertices and . The graph is connected and its vertex set is .
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.