트리에서 거리가 1 또는 2인 정점을 연결한 그래프가 주어질 때, 차수가 3 이하인 원래 트리를 복원한다.
어려움9그래프트리구현완전 탐색아직 제출이 없습니다시간 제한10초메모리 제한512 MBBafuko is a gifted student. Despite being a teenager, she is studying advanced algorithms now. She just learned about graphs and trees. The instructor of the class gave a programming assignment today. This task is about recovering the adjacency list of a tree graph GT = (V, E) from a given undirected graph GU = (V, F). The properties of GT and GU are listed as follows.
You, as a professional programmer, will like to finish the assignment in 20 minutes and brag about how easy it is while playing Bafuko’s favorite game — Super Smash Sisters. Let’s see if you can do it!
First line contains a number T indicating the number of test cases. For each test case, the first line contains a number n indicating the number of vertices in the tree. Then n lines follow. The i-th line descibes the neighbors of i in GU. It is started by ci, the numbers of neighbors of i, then ci distinct numbers vi,1, . . . , vi,ci follow, where {i, v1}, . . . , {i, vci} ∈ F are edges in the given graph GU.
For each test case, please output n lines to describe the adjacency list of the tree graph GT. For the i-th line, please ouput the number of neighbors of i and then the neighbors of i in ascending order. Separate adjacent numbers by a space.