Logo
(追記) (追記ここまで)

31054번 - Cowntact Tracing 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB25101045.455%

문제

Farmer John has $N$ (2ドル\le N\le 10^5$) cows labeled 1ドル\dots N,ドル 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 $Q$ (1ドル\le Q\le 20$) different values for the number of nights, each an integer in the range $[0,N]$. 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 $N$.

The next line contains a bit string of length $N,ドル where the $i$th bit is 1 if the $i$th cow is infected and 0 otherwise. At least one cow is infected.

The next $N-1$ lines contain the edges of the tree.

Then $Q,ドル followed by the $Q$ values for the number of nights.

출력

$Q$ lines, the answers for each number of nights, or $-1$ 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

For the first four queries, one possibility is that just cow 3 started with the illness. For the fifth query (1 night), one possibility is that cows 2 and 4 started with the illness. For the sixth query (0 nights), one possibility is that all five cows started with the illness.

예제 입력 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

For the first query (0 nights), one possibility is that all ten cows started with the illness. For the second query (1 night), one possibility is that cows 2, 7, and 9 started with the illness. For the third query (2 nights), one possibility is that cows 2 and 9 started with the illness. For the fourth to eleventh queries, one possibility is that just cow 7 started with the illness.

예제 입력 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

For the first query (0 nights), one possibility is that cows 1, 2, and 3 started with the illness. For the second query (1 night), one possibility is that just cow 2 started with the illness. For the third query (2 nights), one possibility is that just cow 1 started with the illness. For the fourth through sixth queries, there is no consistent possibility.

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2023 December Contest > Platinum 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /