atcoder#AGC008F. [AGC008F] Black Radius

[AGC008F] Black Radius

Score : 19001900 points

Problem Statement

There is a tree with NN vertices. The vertices are numbered 11 through NN. For each 1iN11 \leq i \leq N - 1, the ii-th edge connects vertices aia_i and bib_i. The lengths of all the edges are 11.

Snuke likes some of the vertices. The information on his favorite vertices are given to you as a string ss of length NN. For each 1iN1 \leq i \leq N, sis_i is 1 if Snuke likes vertex ii, and 0 if he does not like vertex ii.

Initially, all the vertices are white. Snuke will perform the following operation exactly once:

  • Select a vertex vv that he likes, and a non-negative integer dd. Then, paint all the vertices black whose distances from vv are at most dd.

Find the number of the possible combinations of colors of the vertices after the operation.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1ai,biN1 \leq a_i, b_i \leq N
  • The given graph is a tree.
  • s=N|s| = N
  • ss consists of 0 and 1.
  • ss contains at least one occurrence of 1.

Partial Score

  • In the test set worth 13001300 points, ss consists only of 1.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

a2a_2 b2b_2

::

aN1a_{N - 1} bN1b_{N - 1}

ss

Output

Print the number of the possible combinations of colors of the vertices after the operation.

4
1 2
1 3
1 4
1100
4

The following four combinations of colors of the vertices are possible:

334d566ec1f4f38d23cd580044f1cd07.png

5
1 2
1 3
1 4
4 5
11111
11

This case satisfies the additional constraint for the partial score.

6
1 2
1 3
1 4
2 5
2 6
100011
8