## Baltic OI '17 P6 - Cat in a tree

View as PDF

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 1G

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Baltic Olympiad in Informatics: 2017 Day 2, Problem 3

A cat lives in a tree that has nodes. She will demarcate her territory by marking some of the tree nodes. Marked nodes may not be closer to each other than distance . Find the maximum number of nodes that the cat can mark.

#### Input Specification

First line has two integers, and . The th node is the root node of the tree. Then follows lines, the th of which contain a single integer with (starting with ). This means that node is connected to node .

#### Constraints

We always have . For subcases, the inputs have these further restrictions:

• Group 1: 11 points
• Group 2: 40 points
• Group 3: 49 points No further restrictions.

#### Output Specification

Output should contain one integer: the maximum number of nodes that can be marked.

#### Sample Input 1

4 3
0
0
1

#### Sample Output 1

2

#### Sample Input 2

3 1000
0
0

#### Sample Output 2

1