22149_Tree

2022-5-16 18:21| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506151330500-Problem List-采集的数据-后羿采集器.html

Pro.ID

22149

Title

Tree

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22149

AC

1

Submit

2

Ratio

50.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    In this problem, you are given a value S, and a tree. There is a positive integer in each node of the tree. You are asked how many pathes are there which sum up to S. The depth of nodes in the path must be in increasing order. We assume node 1 is the root. The depth of the root is 0, and its children's depth is 1, etc. The path doesn't have to be from the root.

    输入

    The first line contains two integers N and S, where N ( 1 ≤ N ≤ 1000000 ) is the number of nodes in the tree.

    The next line contains N positive integers, the i-th integer is in node i.

    Then the next N-1 line each contains two integer x, y, meaning that y is the child of x.

    输出

    Description

    In this problem, you are given a value S, and a tree. There is a positive integer in each node of the tree. You are asked how many pathes are there which sum up to S. The depth of nodes in the path must be in increasing order. We assume node 1 is the root. The depth of the root is 0, and its children's depth is 1, etc. The path doesn't have to be from the root.

    Input

    The first line contains two integers N and S, where N ( 1 ≤ N ≤ 1000000 ) is the number of nodes in the tree.

    The next line contains N positive integers, the i-th integer is in node i.

    Then the next N-1 line each contains two integer x, y, meaning that y is the child of x.

    Output

    Just output in a single line the number of paths which sum up to S.

    Sample Input

    3 3
    1 2 3
    1 2
    1 3

    Sample Output

    2

    Source

    样例输入

    3 3
    1 2 3
    1 2
    1 3

    样例输出

    2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部