编程介的小学生 2019-09-21 21:41 采纳率: 20.5%
浏览 53

Encode the tree 怎么做到的呢

Problem Description
Given n labeled vertices, there are nn-2 different trees. The number is too large, but Wiskey want to use a way to encode the tree that make a unique sequence associated with the labeled tree.

Follow this way:
1.Select the vertex u which degree is 1 and the labeled number is the minimum. Example, u = 4.
2.Select the neighbor v of u, exists the edge which u to v. Example, v = 1.
3.Delete the edge from the tree. Example, the edge of 1-4 will be deleting.
4.Repeat the first step, until only two vertices left.
5.We will get the sequence {u1, u2… un-2} and {v1, v2… vn-2}.
Now, give you the v sequence, tell me the u sequence.

Input
First line will contain one integer mean how many cases will follow by.
N represents the number of vertices, and the label start from 1. (3 <= N <= 100).
The next N-2 numbers mean the v sequence.

Output
Output the u sequence in one line, separate by a blank space.

Sample Input
1
8
1 2 1 3 3 5

Sample Output
4 6 2 1 7 3

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题