Chocofest

0

0 votes
Medium
Problem

A chocolate shop has n different chocolates numbered from 1 to n. Each chocolate is of some type but you don't know the exact type of each one. You are only given some pairs of chocolates which are of same type.

Now, the owner is in mood to throw a party. So, he wants to create groups of chocolates to  distribute among his friends such that each chocolate belongs to only one group. In any particular group, chocolates are such that no two chocolates are of same type.

Find the minimum number of groups that the owner can make.

INPUT: 

The first line contains integer n (1 ≤ n ≤ 10^5) — the number of chocolates.

The next n lines contain the integers Ci (1 ≤ Ci ≤ n or Ci = -1) meaning that cholocate Ci and i-th chocolate are of same type. If Ci is -1, then it means that you are not given which chocolate is i-th chocolate of same type to.

Output:

Print a single integer denoting the minimum number of groups that will be formed in the party.

 

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first example, four groups are sufficient, for example:

  • Chocolate 1, 5
  • Chocolate 2
  • Chocolate 3
  • Chocolate 4
Editor Image

?