

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
頂点の木があります。 頂点は から まで番号が振られています。 各 について、 番目の辺は頂点 と を繋いでいます。 辺の長さはすべて です。
いくつかの頂点はすぬけ君のお気に入りです。
お気に入りの頂点の情報は、長さ の文字列 として与えられます。
各 について、頂点 がお気に入りならば は 1
で、頂点 がお気に入りでないならば は 0
です。
最初、頂点はすべて白色です。 すぬけ君は次の操作をちょうど 回だけ行います。
- お気に入りの頂点 をひとつ選び、非負整数 をひとつ選ぶ。 頂点 から距離 以内の頂点をすべて黒く塗る。
最終的な頂点の色の組合せとして考えられるものは何通りか求めてください。
制約
- グラフは木である。
- は
0
と1
のみからなる。 - には
1
が含まれる。
部分点
- 点分のデータセットでは、 は
1
のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
出力
最終的な頂点の色の組合せとして考えられるものは何通りか出力せよ。
入力例 1Copy
4 1 2 1 3 1 4 1100
出力例 1Copy
4
次の 通りです。

入力例 2Copy
5 1 2 1 3 1 4 4 5 11111
出力例 2Copy
11
このケースは部分点の制約を満たします。
入力例 3Copy
6 1 2 1 3 1 4 2 5 2 6 100011
出力例 3Copy
8
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.
Sample Input 1Copy
4 1 2 1 3 1 4 1100
Sample Output 1Copy
4
The following four combinations of colors of the vertices are possible:

Sample Input 2Copy
5 1 2 1 3 1 4 4 5 11111
Sample Output 2Copy
11
This case satisfies the additional constraint for the partial score.
Sample Input 3Copy
6 1 2 1 3 1 4 2 5 2 6 100011
Sample Output 3Copy
8