아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

An Unsure Catch

시간 제한8초메모리 제한256 MB

요약
n개 정점의 함수 그래프에서 한 번의 공격으로 모든 죄수를 잡을 수 있도록 간선을 다시 지정할 때 필요한 최소 변경 수와, 그 최소값까지의 각 예산별로 잡을 수 있는 최대 죄수 수를 구한다.
난이도

보통10점 중 7점

유형
그래프, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Some prisoners have managed to escape from the prison! Your job is to get them back.

At time 0, there are nn prisoners out in the city, each at a different position. We label these positions from 11 to nn.

Your colleagues have made a plan to block as many road as possible so that there will be only one way out for each position. Once in an hour, the prisoners at position ii will leave and arrive at position a_i(1≤a_i≤n)a\_i(1 \leq a\_i \leq n) immediately.

You can arrange an assault at any integer time at any position. Every prisoner at the same location at that time will be arrested. However, you can only attack once, after that all the prisoners on the run will leave the city.

After consideration, you decide to contact your colleagues to change their plan. Specifically, you can change some a_ia\_i before time 0 (1≤a_i≤n)1 \leq a\_i \leq n) must still hold after changing).

Now you want to know, what's the minimum number of a_ia\_i to change (let's denote the answer as KK) in order to catch all the prisoners. You also want to know, if you can change a_ia\_i for at most jj (j∈0,1,2,…,K)(j \in \\{0, 1, 2, \dots, K\\}) times, how many prisoners at most can you arrest. Write a program to solve the problem.

입력

There are multiple test cases. The first line of the input contains an integer TT (1≤T≤104)(1 \leq T \leq 10^4), indicating the number of test cases. For each test case:

The first line contains an integer nn (1≤n≤105)(1 \leq n \leq 10^5), indicating the number of prisoners and positions.

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \dots, a\_n (1≤a_i≤n)(1 \leq a\_i \leq n), their meanings are described above.

For only about 5 cases will nn larger than 5050.

출력

For each test case output two lines.

For the first line, print an integer KK, indicating the least number of a_ia\_i to change so that you can arrest all the prisoners.

For the second line, print K+1K+1 integers separated by one space, indicating the number of prisoners you can arrest at most if you can change a_ia\_i for at most 0,1,2,…,K0, 1, 2, \dots, K times.

예제1

  1. 예제 1

    입력
    2
    1
    1
    10
    2 3 1 4 5 7 6 6 6 7
    
    예상 출력
    0
    1
    3
    3 6 9 10