Mafia
Time limit2sMemory limit128 MB
Each mobster aims at one target; find the minimum and maximum possible number of deaths over all shooting orders.
- Level
Medium7 of 10
- Topics
- Graph, Greedy, Implementation
- Solved
- No attempts yet
Problem
mobsters face off in a tense standoff. Each mobster has drawn a pistol and permanently aims it at exactly one of the mobsters (possibly at himself). If the shooting begins, it proceeds under this code of honour:
- The mobsters fire one at a time, in some order; at any moment at most one shot is fired.
- No shooter ever misses. The target dies instantly and can no longer fire.
- Every mobster fires exactly once, unless he is killed before his turn to shoot arrives.
- A mobster never changes his chosen target. If that target is already dead when he fires, the shot merely hits a corpse and causes no new casualty.
The order in which the mobsters shoot is not fixed, and different orders can lead to a different number of deaths. Knowing only who aims at whom, determine the minimum and the maximum possible number of casualties over all shooting orders.
Input
The first line contains one integer (), the number of mobsters, numbered from to .
The second line contains integers (), separated by single spaces, where is the mobster that mobster aims at. Note that is allowed, meaning mobster aims at himself.
Output
Print a single line with two integers separated by one space: the minimum and the maximum possible number of casualties.