import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static int n;
static int arr[] = new int [101];
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
ArrayList<Integer> aList = new ArrayList<Integer>();
int i;
n = scan.nextInt();
for (i = 1; i <= n; i++) {
arr[i] = scan.nextInt();
}
for (i = 1; i <= n; i++) {
if (check(i)) {
aList.add(i);
}
}
System.out.println(aList.size());
for (int t:aList) {
System.out.println(t);
}
}
private static boolean check(int start) {
// TODO Auto-generated method stub
int next = arr[start];
int visit[] = new int [101];
visit[start] = 1;
while (visit[next] == 0) {
visit[next]=1;
next = arr[next];
}
if (next == start) return true;
return false;
}
}
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=731&sca=2080
'정올문제소스코드' 카테고리의 다른 글
2817 : 로또(Lotto) (0) | 2022.03.18 |
---|---|
1021 : 장난감조립 (0) | 2021.12.05 |
1175 : 주사위 던지기2 (0) | 2021.12.05 |
1169 : 주사위 던지기1 (0) | 2021.12.05 |
1161 : 하노이1 (0) | 2021.12.05 |