给定一棵树
(0,1)
(0,7)
(0,12)
(0,13)
(0,15)
(1,2)
(1,4)
(1,6)
(1,7)
(2,3)
(2,5)
(2,6)
(3,4)
(3,5)
(7,8)
(8,9)
(8,10)
(8,11)
(9,10)
(9,11)
(12,13)
(13,14)
(13,15)
0代表根节点,每一数组代表两节点间有无向边。请问,如何判断某节点是否是另一节点的祖先?谢谢
(0,1)
(0,7)
(0,12)
(0,13)
(0,15)
(1,2)
(1,4)
(1,6)
(1,7)
(2,3)
(2,5)
(2,6)
(3,4)
(3,5)
(7,8)
(8,9)
(8,10)
(8,11)
(9,10)
(9,11)
(12,13)
(13,14)
(13,15)
0代表根节点,每一数组代表两节点间有无向边。请问,如何判断某节点是否是另一节点的祖先?谢谢
1, How do you represent a single Node in the Graph?
2, How do you represent a single edge in the Graph?
3, How do you build the Graph from your input?If there is a path from Node A to Node B, then A is a ancestor of B.