The only difference between easy and hard versions is constraints.
There are nn kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the pi-th kid (in case of i=pi the kid will give his book to himself). It is guaranteed that all values of pipi are distinct integers from 1to nn (i.e. p is a permutation). The sequence pp doesn't change from day to day, it is fixed.
For example, if n=6 and p=[4,6,1,3,5,2] then at the end of the first day the book of the 1-st kid will belong to the 4-th kid, the 2-nd kid will belong to the 6-th kid and so on. At the end of the second day the book of the 1-st kid will belong to the 3-th kid, the 2-nd kid will belong to the 2-th kid and so on.
Your task is to determine the number of the day the book of the i-th child is returned back to him for the first time for every i from 1 to n.
Consider the following example: p=[5,1,2,4,3]. The b
B - Books Exchange (easy version) (CodeForces - 1249B1)
最新推荐文章于 2021-12-02 17:18:54 发布
这是一个关于求解每个孩子手中书籍经过多少次交换后回到自己手中的问题,每组示例包含一个整数n和一个表示交换顺序的数组p,p是一个n个不同的整数的排列。题目要求输出每个孩子书籍返回给自己所需的天数。
摘要由CSDN通过智能技术生成