Problem1297--树中节点的祖先

1297: 树中节点的祖先

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1122  Solved: 493
[Submit] [Status] [Web Board] [Creator:]

Description

PIPI有一棵结点值均不相同的二叉树,现在他想知道某结点的祖先结点有哪些,你能帮PIPI解决这个问题吗?

比如说值为13的结点的祖先为 8 10 14

Input

第一行按照先序输入一棵二叉树,其中空节点用 -1 表示。
第二行输入待查询结点的值。

Output

输出一行,代表该结点的祖先节点,从根节点开始输出。若树中无该结点,输出"No Node!"。若树中某结点无祖先,输出 "No Ancestor!"

Sample Input

8 3 1 -1 -1 6 4 -1 -1 7 -1 -1 10 -1 14 13 -1 -1 -1
13

Sample Output

8 10 14

Source/Category