Scheme(翻译 )

来源:https://codeforces.com/contest/22/problem/E

Scheme

To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third member, and so on; i.e. a person with index i got a person with index fi, to whom he has to call, if he learns the news. With time BolgenOS community members understood that their scheme doesn't work sometimes — there were cases when some members didn't learn the news at all. Now they want to supplement the scheme: they add into the scheme some instructions of type (xi, yi), which mean that person xi has to call person yi as well. What is the minimum amount of instructions that they need to add so, that at the end everyone learns the news, no matter who is the first to learn it?

Input

The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.

Output

In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.

Examples

input

3
3 3 2

output

Copy

1
3 1

input

7
2 3 1 3 4 4 1

output

3
2 5
2 6
3 7

 翻译:

‎为了尽快了解有关他们最喜欢的全新操作系统的最新消息,来自Nizhni Tagil的BolgenOS社区决定开发一个方案。根据这个方案,一个社区成员,谁是第一个了解这个消息的人,打电话给其他一些成员,后者,反过来,打电话给一些第三个成员,依此类推;即一个有索引的人‎‎,我‎‎得到了一个有索引的人‎f‎我‎‎,如果他得知消息,他必须打电话给谁。随着时间的推移,BolgenOS社区成员明白他们的计划有时不起作用 - 在某些情况下,一些成员根本没有了解新闻。现在他们想补充这个方案:他们在方案中‎‎添加了‎‎一些类型的指令。‎(x‎我‎‎和‎‎我‎)‎,这意味着那个人‎x‎我‎‎必须打电话给人‎‎和‎‎我‎‎也。他们需要添加的最小指令量是多少,以便最终每个人都能学习新闻,无论谁是第一个学习它的人?‎

‎输入‎

‎第一个输入行包含数字‎‎n‎‎ ‎ (2 ≤ n ≤ 105‎BolgenOS 关于社区成员的数量。第二行包含‎‎n 个‎‎空格分隔的整数‎f‎i(1 ≤ fi ≤ n, i ≠ fi)一个人的索引,向他调用索引‎‎i‎‎的人。‎

‎输出‎

‎在第一行中输出一个数字 — 要添加的指令的最小数量。然后输出一个可能的变体,将这些指令添加到方案中,每行一条指令。如果解决方案不是唯一的,请输出任何解决方案。‎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值