Problem E
Balloon Battle
For your birthday party you have organized a giant water balloon battle, and the battle is about to start! Everyone at your party has one water balloon, and stands at least $6$ feet away from anyone else (giving enough time to run away just in case one of your guests turns into a zombie unexpectedly). At time $t=0$, each person takes aim at someone else. But then, everyone pauses.
You see, since it is only $10^\circ $C ($50^\circ $F) no one really wants to get wet, although they would like to see others get wet. (Since your birthday is in February, a water balloon battle was a strange choice.) Everyone looks around for one second to see who is aiming at who. If, after looking around, a person sees that no one else is aiming at them, then they will definitely throw their water balloon at time $t=1$, since they know they won’t get wet no matter what. Otherwise, if at least one other person is aiming at them, they won’t throw their balloon—unless they get wet, that is! If they ever get wet, they will instantly throw their balloon, since they are already wet anyway so they might as well.
Everyone at your party is a world-class water balloon fighter; you can assume that each person who throws a balloon will definitely hit the person they are aiming at, and it takes $1$ second for each balloon to travel through the air to its target. So, for example, if person $1$ throws their balloon towards person $2$ at time $t = 1$, it will hit person $2$ at time $t = 2$—at which point person $2$ will instantly throw their balloon, hitting their target at time $t = 3$, and so on. The battle continues until no one wants to throw any more balloons.
You see all this and wonder: how many people will stay dry? And how long will the chaos last? If you can yell out your correct predictions just before everyone starts throwing, your friends will all be very impressed.
Input
The first line of input consists of a single integer $2 \leq n \leq 10^5$, the number of people at your party. This will be followed by $n$ more lines, each containing a single integer; the integer on the $i$th line specifies who person $i$ is aiming at (the people are numbered from $1$ to $n$). Obviously, no one ever aims at themselves.
Output
Output a single line containing two space-separated integers: the number of people who will stay dry, and the latest time at which anyone will get hit by a water balloon. If no one will get hit by a water balloon, the second number should be $0$.
| Sample Input 1 | Sample Output 1 |
|---|---|
2 2 1 |
2 0 |
| Sample Input 2 | Sample Output 2 |
|---|---|
3 3 1 2 |
3 0 |
| Sample Input 3 | Sample Output 3 |
|---|---|
4 2 3 4 2 |
1 5 |
