#P2279. [HNOI2003] 消防局的设立

    ID: 1250 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2003各省省选湖南深度优先搜索,DFS树形 dp

[HNOI2003] 消防局的设立

Description

In 2020, humans established a large cluster of bases on Mars, with a total of nn bases. To save materials at the beginning, humans built only n1n-1 roads to connect these bases, and every pair of bases can be reached via roads, so all the bases form a large tree structure. If traveling from base A to base B requires at least dd roads (i.e., the length of the shortest path is dd), we define the distance from base A to base B to be dd.

Because Mars is very dry and fires occur frequently, humans decided to build several fire stations. Fire stations can only be built in bases, and each fire station can extinguish fires at any base whose distance from it does not exceed 22.

Your task is to compute the minimum number of fire stations needed to ensure that whenever a fire occurs at any base on Mars, the firefighters can extinguish it in time.

Input Format

The first line contains nn (1n10001 \leq n \leq 1000), the number of bases on Mars.
For each i=2,3,,ni = 2, 3, \dots, n, line ii contains a positive integer aia_i, indicating that there is a road between base ii and base aia_i. To make the tree representation concise, ai<ia_i < i.

Output Format

Output a single positive integer, the minimum number of fire stations required so that any base that catches fire can be extinguished in time.

6
1
2
3
4
5

2

Hint

Translated by ChatGPT 5