Please do in ruby only. Correct and detailed answer will upvoted else downvoted.   To learn as quickly as time permits the most recent news about their number one in a general sense new working framework, BolgenOS people group from Nizhni Tagil chose to foster a plan. As per this plan a local area part, who is quick to become familiar with the news, calls another part, the last mentioned, in his turn, calls some third part, etc; for example an individual with list

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter1: Creating Java Programs
Section: Chapter Questions
Problem 10RQ
icon
Related questions
Question
100%

Please do in ruby only. Correct and detailed answer will upvoted else downvoted.

 

To learn as quickly as time permits the most recent news about their number one in a general sense new working framework, BolgenOS people group from Nizhni Tagil chose to foster a plan. As per this plan a local area part, who is quick to become familiar with the news, calls another part, the last mentioned, in his turn, calls some third part, etc; for example an individual with list I got an individual with list fi, to whom he needs to call, on the off chance that he learns the news. With time BolgenOS people group individuals comprehended that their plan doesn't work at times — there were situations when a few individuals didn't become familiar with the news by any stretch of the imagination. Presently they need to enhance the plan: they add into the plan a few directions of type (xi, yi), which imply that individual xi needs to call individual yi too. What is the base measure of guidelines that they need to add all in all, that toward the end everybody learns the news, regardless of who is quick to learn it? 

Input :The initially input line contains number n (2 ≤ n ≤ 105) — measure of BolgenOS people group individuals. The subsequent line contains n space-isolated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — record of an individual, to whom calls an individual with list I. 

Output :In the primary line output one number — the base measure of guidelines to add. Then, at that point, output one of the potential variations to add these directions into the plan, one guidance in each line. In the event that the arrangement isn't remarkable, output any

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT