#t459. 找树根和孩子

找树根和孩子

The Tree Root and Its Children

Problem Background

Special for beginners, ^_^

Problem Description

Given a tree, output its root root, the node max with the most children, and that node's children.

Input Format

The first line: nn (number of nodes ≤100\le 100), mm (number of edges ≤200\le 200).

The following mm lines each contain two nodes xx and yy, meaning yy is a child of xx (x,y≤100x, y \le 100).

Output Format

The first line: the tree root: root.

The second line: the node max with the most children.

The third line: max's children.

Sample Input

8 7
4 1
4 2
1 3
1 5
2 6
2 7
2 8

Sample Output

4
2
6 7 8

Constraints

n≤100, m≤200n \le 100,\ m \le 200.

Time limit 11 s, memory 10241024 KiB per test case.

Hint

  • The root is the only node that is never listed as a child (no parent edge points to it).
  • Build the child lists, then the node whose list is longest is max.