QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#15068. isomorphism

Estadísticas

In an undirected tree, a node with a degree of 2 is called a "fake node," and all other nodes are called "true nodes." The "simplified tree" of an undirected tree consists of all the true nodes of the original tree. An edge exists between two true nodes in the simplified tree if and only if they are connected by an edge in the original tree, or if there is a path between them in the original tree where all intermediate nodes are fake nodes. Two undirected trees are said to be "substantially isomorphic" if their respective simplified trees are isomorphic—that is, there exists a one-to-one correspondence between the nodes such that any two nodes in one tree are connected by an edge if and only if their corresponding nodes in the other tree are connected by an edge. Given several undirected trees, keep only one from each set of substantially isomorphic trees and remove the others. Count the number of remaining non-substantially isomorphic trees and output the number of nodes in their simplified trees in non-decreasing order.

Input

The first line contains a single positive integer $m$, followed by $m$ undirected trees. For each tree, the first line contains the number of nodes $n$ (nodes are labeled from $1$ to $n$), followed by $n-1$ lines each containing two distinct integers between $1$ and $n$ separated by a space, representing an undirected edge between these two nodes. There are no empty lines between trees.

Output

The first line outputs a positive integer $m_0$ ($1 \le m_0 \le m$), representing the number of non-substantially isomorphic trees. The second line contains $m_0$ positive integers in non-decreasing order, representing the number of nodes in the simplified trees of these $m_0$ trees, separated by spaces.

Constraints

  • 30% of the data: $2 \le m \le 10$, $2 \le n \le 10$
  • 60% of the data: $2 \le m \le 20$, $2 \le n \le 300$
  • 100% of the data: $2 \le m \le 20$, $2 \le n \le 10000$

Examples

Input 1

2
4
1 4
2 4
3 4
5
1 3
2 3
3 4
4 5

Output 1

1
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.