atcoder#AGC008F. [AGC008F] Black Radius
[AGC008F] Black Radius
Score : points
Problem Statement
There is a tree with vertices. The vertices are numbered through . For each , the -th edge connects vertices and . The lengths of all the edges are .
Snuke likes some of the vertices.
The information on his favorite vertices are given to you as a string of length .
For each , is 1
if Snuke likes vertex , and 0
if he does not like vertex .
Initially, all the vertices are white. Snuke will perform the following operation exactly once:
- Select a vertex that he likes, and a non-negative integer . Then, paint all the vertices black whose distances from are at most .
Find the number of the possible combinations of colors of the vertices after the operation.
Constraints
- The given graph is a tree.
- consists of
0
and1
. - contains at least one occurrence of
1
.
Partial Score
- In the test set worth points, consists only of
1
.
Input
The input is given from Standard Input in the following format:
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:
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