Submission #2227115


Source Code Expand

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;i ++) {
			a[i] = sc.nextInt();
		}
		int bnum = a[0], find = 0,cnt = 0;
		for(int i = 0;i < N * (N - 1) / 2;i ++) {
			bnum = a[bnum - 1];
			cnt ++;
			if(bnum == 2) {
				find = 1;
				cnt ++;  //最後にボタン2が光るボタンを押す
				break;
			}
		}
		if(find == 1) System.out.println(cnt);
		else System.out.println("-1");
	}
}

Submission Info

Submission Time
Task A - Expired?
User ne290179
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 559 Byte
Status RE
Exec Time 220 ms
Memory 534996 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
RE × 3
MLE × 1
RE × 8
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt RE 100 ms 21332 KB
02.txt RE 94 ms 20680 KB
03.txt RE 95 ms 21972 KB
04.txt RE 111 ms 39636 KB
05.txt MLE 220 ms 534996 KB
06.txt RE 97 ms 20944 KB
s1.txt RE 94 ms 19924 KB
s2.txt RE 97 ms 22996 KB
s3.txt RE 96 ms 19028 KB