1539: 多叉树 - 打印从根到某结点的路径

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:32 Solved:11

Description

给定一棵多叉树,输出从根到某个节点的路径

Input

第一行:n(结点个数≤100,结点编号从1到n)k 需要打印路径的结点编号
接下来 n-1 行:每行两个结点编号 x 和 y,表示 y 是 x 的子结点 (x,y≤100)。

Output

输出从根节点到编号 k 的节点的路径

Sample Input Copy

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

Sample Output Copy

4->2->6