#P3472. [POI2008] MAF-Mafia

[POI2008] MAF-Mafia

题目描述

Mob feud rages in Equatorial Byteotia. The mob bosses have come to the country's capital, Byteburg, to settle the dispute.

Negotiations were very tense, and at one point the trigger-happy participants drew their guns.

Each participant aims at another with a pistol.

Should they go on a killing spree, the shooting will go in accordance with the following code of honour:

the participants shoot in a certain order, and at any moment at most one of them is shooting, no shooter misses, his target dies instantly, hence he may not shoot afterwards, everyone shoots once, provided he had not been shot before he has a chance to shoot, no participant may change his first target of choice, even if the target is already dead (then the shot causes no further casualties).

An undertaker watches from afar, as he usually does. After all, the mobsters have never failed to stimulate his business.

He sees potential profit in the shooting, but he would like to know tight estimations. Precisely he would like to know the minimum and maximum possible death rate.

The undertaker sees who aims at whom, but does not know the order of shooting.

You are to write a programme that determines the numbers he is so keen to know.

Task Write a programme that:

reads from the standard input what target each mobster has chosen, determines the minimum and maximum number of casualties, writes out the result to the standard output.

输入格式

The first line of the standard input contains the number of participants nn (1n1,000,0001\le n\le 1{,}000{,}000).

They are numbered from 11 to nn.

The second line contains nn integers s1,s2,,sns_1,s_2,\cdots,s_n, separated by single spaces, 1sin1\le s_i\le n.

sis_i denotes the number of ithi^\mathrm{th} participant's target.

Note that it is possible that si=is_i=i for some ii (the nerves, you know).

输出格式

Your programme should write out two integers separated by a single space in the first and only line of the standard output. These numbers should be, respectively, the minimum and maximum number of casualties resulting from the shooting.

题目大意

nn 个参赛者,对于第 ii 个参赛者,他在初始时刻用手枪瞄准了一个参赛者 aimi\mathit{aim}_i,(aimi\mathit{aim}_i 可以是 ii)。然后他们按某个顺序开枪,且任意时刻只有一个人开枪。所以,对于不同的开枪顺序,最后被击中的人数也不同。

你需要求出:在所有的开枪顺序中,最少和最多的被击中人数。

对于 100%100\% 的数据,1n1061\leq n \leq 10^61aimin1\leq \mathit{aim}_i \leq n

8
2 3 2 2 6 7 8 5

3 5