GlobeX Cup '18 S1 - Code Copiers

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Memory limit: 128M

Author:
Problem type
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

Code copying is a major problem on many online programming judges. There are N coders, of which some of them copy code from others. Coder i knows that only coder a_i copied from them.

There is always some "sources" from which coders copy from. A "source" is defined as a coder who does not copy from anyone. Your task is to find out how many "sources" there are.

Input Specification

The first line will contain the integer N (1 \le N \le 10^6), the number of coders there are.

The second line will contain N integers, a_1, a_2, \dots, a_N (0 \le a_i < i). The i^{th} integer means that coder a_i copies from coder i. If a_i=0, this means no coders copies from coder i.

Output Specification

Output the number of "sources".

Subtasks

Subtask 1 [20%]

N \le 1\,000

Subtask 2 [80%]

No further constraints.

Sample Input 1

5
0 1 1 3 2

Sample Output 1

2

Sample Input 2

9
0 1 1 3 4 5 6 4 6

Sample Output 2

4

Comments

There are no comments at the moment.