Given an undirected graph , where is a set of vertices and is a set of edges, a connected component of is a maximal connected subgraph of . In other words, every two vertices and of belong to the same connected component if and only if there is a path from to . In the example below there are 7 connected components.
Given two undirected (sub)graphs and , and are said to be isomorphic if and only if there exists a bijection such that for every , . In the example above, the connected component with vertices is isomorphic to exactly two connected components: those with vertices and .
Write a program such that, for every given undirected graph , computes the number of pairs (not counting order) of connected components of that are isomorphic. For instance, the result for the graph above is 4: with , with , with , and with .
Input consists of several graph descriptions. Each one begins with the number of vertices and the number of edges . Follow pairs of different numbers, each between 0 and . You can assume . No edges are repeated. Every given connected component has at most 6 vertices.
For every graph, print the number of connected components that are pairwise isomorphic.
Author: Salvador Roura
Generation: 2026-01-25T11:28:05.398Z
© Jutge.org, 2006–2026.
https://jutge.org