RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0566

Watching Cowflix

Diamond III 다이아몬드 III
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

*Note: The time limit for this problem is 3s, 1.5x the default.*

Bessie likes to watch shows on Cowflix, and she watches them in different
places. Farmer John's farm can be represented as a tree with \(N\)
(\(2 \leq N \leq 2\cdot 10^5\)) nodes, and for each node, either Bessie watches
Cowflix there or she doesn't. It is guaranteed that Bessie watches Cowflix in
at least one node.

Unfortunately, Cowflix is introducing a new subscription model to combat
password sharing. In their new model, you can choose a connected component of
size \(d\) in the farm, and then you need to pay \(d + k\) moonies for an account
that you can use in that connected component. Formally, you need to choose a set
of disjoint connected components \(c_1, c_2, \dots, c_C\) so that every node where
Bessie watches Cowflix must be contained within some \(c_i\). The cost of the set
of components is \(\sum_{i=1}^{C} (|c_i|+k)\), where \(|c_i|\) is the number of
nodes in component \(c_i\). Nodes where Bessie does not watch Cowflix do not have
to be in any \(c_i\).

Bessie is worried that the new subscription model may be too expensive for her
given all the places she visits and is thinking of switching to Mooloo. To aid
her decision-making, calculate the minimum amount she would need to pay to
Cowflix to maintain her viewing habits. Because Cowflix has not announced the
value of \(k\), calculate it for all integer values of \(k\) from \(1\) to \(N\).

Problem credits: Danny Mittal

제약

SCORING

  • Inputs 3-5: \(N\le 5000\)
  • Inputs 6-8: \(i\) is connected to \(i+1\) for all \(i\in [1,N)\).
  • Inputs 9-19: \(N\le 10^5\)
  • Inputs 20-24: No additional constraints.

Problem credits: Danny Mittal

입력 형식

The first line contains \(N\).

The second line contains a bit string \(s_1s_2s_3 \dots s_N\) where \(s_i = 1\) if
Bessie watches Cowflix at node \(i\).

Then \(N-1\) lines follow, each containing two integers \(a\) and \(b\)
(\(1 \leq a, b \leq N\)), which denotes an edge between \(a\) and \(b\) in the tree.

출력 형식

The answers for each \(k\) from \(1\) to \(N\) on separate lines.

예제 1
입력
5
10001
1 2
2 3
3 4
4 5
출력
4
6
8
9
10
설명

For \(k\le 3\), it's optimal to have two accounts: \(c_1 = \{1\}, c_2 = \{5\}\). For
\(k\ge 3\), it's optimal to have one account: \(c_1 = \{1, 2, 3, 4, 5\}\).

예제 2
입력
7
0001010
7 4
5 6
7 2
5 1
6 3
2 5
출력
4
6
8
9
10
11
12
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > February > Platinum

태그

평가 및 의견

Watching Cowflix

개요
출제자 난이도 Diamond III 다이아몬드 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Watching Cowflix

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8