문제
Farmer John has () cows labeled , where the connections between cows are described by a tree. Unfortunately, there is a sickness spreading throughout.
Initially, some cows start off infected. Every night, an infected cow spreads the sickness to their neighbors. Once a cow is infected, she stays infected. After some amount of nights, Farmer John realizes that there is an issue so he tests his cows to determine who has the sickness.
You are given () different values for the number of nights, each an integer in the range . For each number of nights, determine the minimum number of cows that could have started with the illness, or that the number of nights is inconsistent with the given information.
입력
The first line contains .
The next line contains a bit string of length , where the th bit is 1 if the th cow is infected and 0 otherwise. At least one cow is infected.
The next lines contain the edges of the tree.
Then , followed by the values for the number of nights.
출력
lines, the answers for each number of nights, or if impossible.
예제 입력 1
5
11111
1 2
2 3
3 4
4 5
6
5
4
3
2
1
0
예제 출력 1
1
1
1
1
2
5
예제 입력 2
10
1111111111
1 2
2 3
2 4
2 5
2 6
6 7
7 8
8 9
9 10
11
0
1
2
3
4
5
6
7
8
9
10
예제 출력 2
10
3
2
1
1
1
1
1
1
1
1
예제 입력 3
5
11100
1 2
2 3
3 4
4 5
6
0
1
2
3
4
5
예제 출력 3
3
1
1
-1
-1
-1
점수
Inputs 4-5: Inputs 6-8: All cows are infected.Inputs 9-11: Inputs 12-23: No additional restrictions.
코드를 제출하려면 로그인이 필요합니다.
로그인