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

30316번 - Losing Leaves 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 (추가 시간 없음) 1024 MB115555052.083%

문제

Here at the Benelux Advanced Phone Company (BAPC), we are the proud owners of the largest telephone network in the Benelux area. Unfortunately, our network has become too large for us to manage properly. As such, we have decided to sell part of our network.

The network of the BAPC consists of interconnected transmission nodes. One transmission node is marked as the central switch. All other nodes have exactly one upstream transmission node. For each transmission node, if we follow the upstream connections, we will finally end up at the central switch. A node is considered a customer transmission node when it is a leaf, i.e. when it has no downstream nodes.

When selling parts of our network, integrity must be maintained. That means that whenever we sell a transmission node $X,ドル we also have to sell nodes downstream of $X$.

Overall, BAPC decided to sell exactly $k$ transmission nodes. While there may be many options to choose these $k$ nodes, we actually want to make our lives as easy as possible: After selling, we want to minimize the number of customer transmission nodes in our network, while maintaining the network's integrity.

As an example, consider the second sample case, visualized in Figure L.1. The three striped red nodes are sold, and the two bold green nodes are the remaining customer nodes.

Figure L.1: Visualization of the second sample input.

입력

The input consists of:

  • One line with two integers $n$ and $k$ (0ドル\leq k < n\leq 10^6$), the number of transmission nodes, and the number of nodes to sell.
  • $n-1$ lines, the \(i\)th of which contains one integer \(p_i\) (\(0 \leq p_i < i\)) indicating that transmission node \(i\) (\(1 \leq i < n\)) has an outgoing connection to node \(p_i\).

The transmission nodes are numbered from \(0\) to \(n - 1\), inclusive. Node 0ドル$ is always the central switch.

출력

Output the minimum number of customer transmission nodes after selling $k$ transmission nodes. Note that if the central switch is the only remaining node, it also counts as a customer node.

제한

예제 입력 1

5 2
0
0
1
1

예제 출력 1

1

예제 입력 2

9 3
0
0
1
1
1
4
5
6

예제 출력 2

2

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2023 Preliminaries L번

  • 문제를 만든 사람: Ragnar Groot Koerkamp
(追記) (追記ここまで)

출처

대학교 대회

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

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