Under construction

Still being built. Things may change

Harvesting Apples at Tree Nodes Within Distance k

Interview

Time limit1sMemory limit512 MB

Summary
Count the apples on vertices whose distance from root 0 is at most k in a given tree.
Level

Easy3 of 10

Topics
Tree, BFS
Solved
No attempts yet

Statement

There is a tree TT with nn vertices and n−1n-1 edges. The vertices are numbered from 0 to n−1n-1, and vertex 0 is the root. Every edge has length 1. Each vertex of TT has either 0 or 1 apple. You want to harvest the apples on the nodes whose distance from the root node is at most kk. Print the number of apples you can harvest.

Input

The first line contains the number of vertices nn and the integer kk, separated by a space.

From the second line onward, the next n−1n-1 lines describe the edges. Each line contains one edge, given as a parent vertex number pp and a child vertex number cc, separated by a space.

The next line contains nn integers, separated by spaces, that give the apple count of each vertex from 0 to n−1n-1. The ii-th number is the number of apples on vertex i−1i-1. Each number is 0 or 1.

Output

Print the number of apples you can harvest on the first line.

Constraints

  • 2≤n≤100,0002 \le n \le 100{,}000
  • 0≤p,c≤n−10 \le p, c \le n-1, p≠cp \ne c
  • The graph formed by the edges is a tree.
  • 0≤k≤n−10 \le k \le n-1
  • The number of apples on each vertex is 0 or 1.

Examples1

  1. Example 1

    Input
    8 2
    0 1
    0 2
    1 3
    1 4
    2 5
    2 6
    6 7
    1 0 0 1 0 1 0 1
    
    Expected output
    3