zoukankan      html  css  js  c++  java
  • Path (path)

    Description


    Given a tree of (n) nodes, the node number is (1 sim n) (the root node number is (1)). For each leaf node, output the path from the root to the leaf.
    Note: The output will be output according to the lexicographic order of the path from smallest to largest.

    Format


    Input

    The first line: the number of (1) (n) indicates the number of nodes in the tree.
    The following (n-1) lines: the number of (2) in each line (x y), indicating that the node (x) is the parent node of the node (y).

    Output

    The number of output rows is equal to the number of leaf nodes, and each row corresponds to the path from the root to the leaf node. The number in the path is the number of the passing node. According to the lexicographic order of the path, output from small to large.

    Sample


    Input

    5
    1 2
    1 3
    2 4
    4 5
    

    Output

    1 2 4 5
    1 3
    

    Sample Explanation

    And (5) are leaf nodes, and the corresponding paths are (1 3) and (1 2 4 5) respectively. The latter has a smaller dictionary order, so the output result is:

    1 2 4 5
    1 3
    

    Sample Code


    Code is not available!
    
  • 相关阅读:
    配色方案及色彩心理学(转)
    CSS中强大的EM
    Link To Sql简单
    改变html中鼠标形状
    JS实现雪花效果
    你真的已经搞懂JavaScript了吗?
    MVC特性
    初识 bower(一)
    学习前端模板引擎 jade (一)
    日志系统
  • 原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13812559.html
Copyright © 2011-2022 走看看