Parallel Universe
Time limit1sMemory limit1024 MB
Given up to a million small trees (each up to 30 nodes), count how many are pairwise non-isomorphic, since Hanna can photograph one tree per distinct topology.
- Level
Medium7 of 10
- Topics
- Tree, Hash map, DFS, Implementation
- Solved
- No attempts yet
Problem

Right now, while the Sogang Programming Contest is being held, countless stars fill the sky over Dasan Hall.
Taehan majors in computer science, but he studies stars as a hobby. Having already proved that parallel universes exist, Taehan became so absorbed in his star research that he turned every star in every parallel universe into a constellation.

A constellation is defined by n stars and n − 1 line segments joining stars, and all stars in one constellation are connected. When defining constellations, Taehan made sure that no parallel universe contains two constellations of the same topology. Two constellations have the same topology if one can be turned into the other by moving the stars without changing the connection relations among them.
Hanna received Taehan's research notebook, which holds information about the constellations, so she can photograph every constellation that exists in the parallel universe we live in. The notebook contains information about every constellation in every parallel universe, but unfortunately it does not say which parallel universe each constellation belongs to.
Using Taehan's notebook, compute the maximum number of photographs Hanna can take. Hanna takes one photograph per constellation.
Input
The first line gives the total number of constellations n across all parallel universes. (1 ≤ n ≤ 106) The total number of stars does not exceed 106.
Starting from the second line, information about each constellation is given.
For each constellation, the first line gives the number of stars s in the constellation. (1 ≤ s ≤ 30)
The next s − 1 lines each give two integers u, v, meaning a connection between stars. (0 ≤ u, v < s, u ≠ v)
For convenience, the stars in each constellation are considered to be numbered 0, 1, 2, ⋯, s − 1, and u v means that star u and star v are connected. Star numbers are ignored when considering the topology of a constellation.
Output
Print the maximum number of photographs Hanna can take.