s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s631901959
p03680
u646412443
1588702719
Python
Python (3.4.3)
py
Runtime Error
238
7980
220
n = int(input()) a = [int(input()) for _ in range(n)] def search(i, p): if p > n: print(-1) exit() elif i == 2: print(p) exit() else: search(a[i-1], p+1) search(1, 0)
s600974518
p03680
u646412443
1588702012
Python
Python (3.4.3)
py
Runtime Error
235
7980
218
n = int(input()) a = [int(input()) for _ in range(n)] def search(i, p): if p > n: print(-1) exit() if i == 2: print(p) exit() else: search(a[i-1], p+1) search(1, 0)
s257526651
p03680
u646412443
1588701896
Python
Python (3.4.3)
py
Runtime Error
229
7980
220
n = int(input()) a = [int(input()) for _ in range(n)] def search(i, p): if i == 2: print(p) exit() elif p > n: print(-1) exit() else: search(a[i-1], p+1) search(1, 0)
s400118729
p03680
u277641173
1588543003
Python
Python (3.4.3)
py
Runtime Error
17
2940
210
n=int(input()) a=[] for i in range(n): a.append(int(input())) keep=1 count=0 ababa=0 for i in range(n): count+=1 keep=a[keep-1] if keep==2: ababa=1 print(count) break if ababa=0: print(-1)
s187873151
p03680
u770077083
1588533244
Python
Python (3.4.3)
py
Runtime Error
17
2940
291
n = int(input()) a = [[int(input())-1, False] for _ in range(n)] a[0][1] = True now = 0 cnt = 0 while True: now = a[now][0] if a[now][1]: print(f"now={now}") print(-1) break a[now][1] = True cnt += 1 if now == 1: print(cnt) break
s089717611
p03680
u328751895
1588394274
Python
Python (3.4.3)
py
Runtime Error
207
18020
155
N = int(input()) a = {} for i in range(N): a[i + 1] = int(input()) for i in range(N): if a[i] == 2: print(i + 1) exit(0) print(-1)
s279843617
p03680
u886297662
1588282691
Python
Python (3.4.3)
py
Runtime Error
176
7084
172
N = int(input()) a = [int(input()) for i in range(N)] i = 0 while cnt <= N: lgt = a[i] cnt += 1 if lgt == 2: print(cnt) break i = lgt - 1 else: print(-1)
s493508076
p03680
u423665486
1588128074
Python
Python (3.4.3)
py
Runtime Error
428
99744
362
import sys from io import StringIO import unittest sys.setrecursionlimit(10**5) def rec(n, a, seen): if seen[n-1]: return -1 if a[n-1] == 2: return seen.count(True) + 1 seen[n-1] = True return rec(a[n-1], a, seen) def resolve(): n = int(input()) a = [] seen = [False]*n for _ in range(n): a.append(int(i...
s216291556
p03680
u423665486
1588128040
Python
Python (3.4.3)
py
Runtime Error
42
5588
363
import sys from io import StringIO import unittest sys.setrecursionlimit(100**5) def rec(n, a, seen): if seen[n-1]: return -1 if a[n-1] == 2: return seen.count(True) + 1 seen[n-1] = True return rec(a[n-1], a, seen) def resolve(): n = int(input()) a = [] seen = [False]*n for _ in range(n): a.append(int(...
s682205424
p03680
u423665486
1588127522
Python
Python (3.4.3)
py
Runtime Error
235
8744
280
def rec(n, a, seen): if seen[n-1]: return -1 if a[n-1] == 2: return seen.count(True) + 1 seen[n-1] = True return rec(a[n-1], a, seen) def resolve(): n = int(input()) a = [] seen = [False]*n for i in range(n): a.append(int(input())) print(rec(1, a, seen)) resolve()
s657086738
p03680
u943057856
1588004639
Python
Python (3.4.3)
py
Runtime Error
17
3060
238
n=int(input()) a=[int(input()) for _ in range(n)] ans=-1 b=a[0] if b==2: print(1) break else: for i in range(n): b=a[b-1] # print(f"b={b}") if b==2: ans=i+2 break print(ans)
s630236282
p03680
u426572476
1587926091
Python
Python (3.4.3)
py
Runtime Error
25
3572
4138
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from math import factorial, sqrt, ceil, gcd from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10 ** 7) # UnionFind class Un...
s736168713
p03680
u564837886
1587884388
Python
Python (3.4.3)
py
Runtime Error
2104
7084
216
n = int(input()) a = [] for i in range(n): a.append(int(input())) p = 1 ans = 0 while True: tmp = p p = a[p-1] a[tmp] = 0 ans += 1 if p == 0: print(-1) break if p == 2: print(ans) break
s413382292
p03680
u564837886
1587883671
Python
Python (3.4.3)
py
Runtime Error
2104
7208
207
n = int(input()) a = [] for i in range(n): a.append(int(input())) memo = [] p = 1 ans = 0 while p == 2 or not p in memo: memo.append(p) p = a[p] ans += 1 if p == 2: print(ans) else: print(-1)
s593440247
p03680
u796842765
1587612642
Python
Python (3.4.3)
py
Runtime Error
2104
7852
246
N = int(input()) a = [int(input()) for _ in range(N)] count = 0 i = 1 x = 0 osita = [0]*N while 2 not in osita and count < N + 10: osita[x] = i i = a[i-1] count += 1 x += 1 if count > N: print(-1) else: print(count-1)
s116526046
p03680
u252964975
1587534978
Python
Python (3.4.3)
py
Runtime Error
201
7084
172
N=int(input()) A = [] for i in range(N): Ai=int(input()) A.append(Ai) on = 1 for i in range(N): on = A[on] if on == 2: print(i) break if i != 2: print(-1)
s884878165
p03680
u766566560
1587093368
Python
Python (3.4.3)
py
Runtime Error
199
7084
211
N = int(input()) a = [int(input()) for _ in range(N)] light = 1 cnt = 0 for i in range(N): if i == 0: nxt = a[0] - 1 else: nxt = a[nxt] if nxt == 2: break else: cnt += 1 print(cnt)
s929233087
p03680
u479638406
1586961382
Python
Python (3.4.3)
py
Runtime Error
189
7084
185
n = int(input()) a = [int(input()) for _ in range(n)] b = 0 cnt = 0 while cnt <= 100000: b = a[b] cnt += 1 if b == 1: break if cnt > 100000: print(-1) else: print(cnt)
s155812023
p03680
u211805975
1586738786
Python
Python (3.4.3)
py
Runtime Error
17
2940
253
n=int(input()) num=[0] ans=0 count=0 k=1 for i in range(n): a=int(input()) num.append(a) for i in range(n+1): k=num[k] count+=1 if k==2: ans=1 break if ans==1: print(count) else: print("-1") # coding: utf-8
s902351930
p03680
u735335967
1586722456
Python
Python (3.4.3)
py
Runtime Error
17
2940
196
n = int(input()) a = [int(input() for i in range(n)] ans = 0 i = 0 while n > 0: ans += 1 if a[i] == 2: print(ans) quit() else: i = a[i]-1 n -= 1 print(-1)
s828419832
p03680
u419963262
1586713311
Python
Python (3.4.3)
py
Runtime Error
231
8068
212
N = int(input()) A = [int(input()) for i in range(N)] def check_num(a,b): if b>N+1: return -1 if A[a]==2: return b else: return check_num(int(A[a])-1,b+1) print(check_num(0,1))
s533048153
p03680
u145231176
1586711587
Python
PyPy3 (2.4.0)
py
Runtime Error
1241
104480
458
from copy import deepcopy n = int(input()) lista = [[] for i in range(n + 1)] ans = 10000000 for i in range(n): a = int(input()) lista[i + 1].append(a) def dfs(now, ignore): global ans if now == 2: ans = min(ans, len(ignore) - 1) for i in lista[now]: if i in ignore: conti...
s838143945
p03680
u145231176
1586711490
Python
PyPy3 (2.4.0)
py
Runtime Error
1237
104224
466
from copy import deepcopy n = int(input()) lista = [[] for i in range(n + 1)] ans = float('inf') for i in range(n): a = int(input()) lista[i + 1].append(a) def dfs(now, ignore): global ans if now == 2: ans = min(ans, len(ignore) - 1) for i in lista[now]: if i in ignore: c...
s729871439
p03680
u852790844
1586634821
Python
Python (3.4.3)
py
Runtime Error
209
7852
243
n = int(input()) a = [int(input()) for i in range(n)] check = [0 for i in range(n)] now = 0 ans = 0 while check[now] == 0: if now == 1: print(ans) break check[now] = 1 now = a[now-1] ans += 1 else: print(-1)
s475477931
p03680
u852790844
1586634520
Python
Python (3.4.3)
py
Runtime Error
18
2940
232
n = int(input()) a = [int(input()) for i in range(n)] check = [0 for i in rangen(n)] now = 0 ans = 0 while check(now) != 0: if now == 1: print(ans) break check[now] = 1: now = a[now-1] else: print(-1)
s371301771
p03680
u920621778
1586123708
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38256
243
n = int(input()) a_list = [] for i in range(n): a_list.append(int(input())) r = -1 num = 1 count = 0 nums = [] while True: num = a_list[num-1] if num in nums: break nums.append(num)) count += 1 if num == 2: r = count break print(r)
s421097228
p03680
u194225526
1586099148
Python
Python (3.4.3)
py
Runtime Error
17
2940
666
import java.util.*; public class Main { public static void main(String args[]) { // 入力 Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); Integer[] a = new Integer[n]; Arrays.setAll(a, i -> Integer.parseInt(sc.next())); sc.close(); /...
s695570110
p03680
u163874353
1585804495
Python
Python (3.4.3)
py
Runtime Error
193
7084
218
n = int(input()) a = [int(input()) for i in range(n)] now = a[0] cnt = 0 for i in range(n): cnt += 1 now = a[now - 1] if a[now] == 2: print(cnt + 1) exit() print("-1")
s411144952
p03680
u440129511
1585687755
Python
Python (3.4.3)
py
Runtime Error
17
3064
229
n=int(input()) a = [map(int,input() for _ in range(n))] nex=[] k=1 for i in range(len(a)): nex.append(a[k-1]) k=nex[-1] if nex[-1]==2: print(len(nex)) break elif len(nex)>=n:print(-1) else:pass
s905768491
p03680
u440129511
1585687623
Python
Python (3.4.3)
py
Runtime Error
251
26156
229
n=int(input()) a = [map(int,input()) for _ in range(n)] nex=[] k=1 for i in range(len(a)): nex.append(a[k-1]) k=nex[-1] if nex[-1]==2: print(len(nex)) break elif len(nex)>=n:print(-1) else:pass
s857149546
p03680
u440129511
1585687533
Python
Python (3.4.3)
py
Runtime Error
149
9496
220
n=int(input()) a = [input() for _ in range(n)] nex=[] k=1 for i in range(len(a)): nex.append(a[k-1]) k=nex[-1] if nex[-1]==2: print(len(nex)) break elif len(nex)>=n:print(-1) else:pass
s516570834
p03680
u440129511
1585687208
Python
Python (3.4.3)
py
Runtime Error
231
21772
308
from itertools import chain n=int(input()) an= [list(input()) for _ in range(n)] a=list(chain.from_iterable(an)) nex=[] k=1 for i in range(len(a)): #if k-1==-1:k-1=0 nex.append(a[k-1]) k=nex[-1] if nex[-1]==2: print(len(nex)) break elif len(nex)>=n:print(-1) else:pass
s639853828
p03680
u440129511
1585686897
Python
Python (3.4.3)
py
Runtime Error
221
17780
247
n=int(input()) a= [list(input()) for _ in range(n)] nex=[] k=1 for i in range(len(a)): #if k-1==-1:k-1=0 nex.append(a[k-1]) k=nex[-1] if nex[-1]==2: print(len(nex)) break elif len(nex)>=n:print(-1) else:pass
s068399936
p03680
u134302690
1585251440
Python
Python (3.4.3)
py
Runtime Error
2104
7852
330
import sys N = int(input()) a = [] for _ in range(N): a.append(int(input())) s = [0] * max(a) s[0] = 1 count = 0 for _ in range(N): for i in range(N): if s[i] == 1: s[i] = 0 s[a[i]-1] = 1 break count += 1 if s[1] == 1: print(count) sys.exit() ...
s059750996
p03680
u016323272
1585153414
Python
Python (3.4.3)
py
Runtime Error
180
7084
169
#ABC065.B N = int(input()) a = [int(input()) for i in range(N)] x = 0 for i in range(N): x = a[x] if x == 2: print(i+1) break else: print(-1)
s823168956
p03680
u016323272
1585153007
Python
Python (3.4.3)
py
Runtime Error
191
7084
172
#ABC065.B N = int(input()) a = [int(input()) for i in range(N)] x = 0 for i in range(N): x = a[x] if a[x] == 2: print(i+1) break else: print(-1)
s715220728
p03680
u016323272
1585152915
Python
Python (3.4.3)
py
Runtime Error
17
3060
172
#ABC065.B N = int(input()) a = [int(input() for i in range(N))] x = 0 for i in range(N): x = a[x] if a[x] == 2: print(i+1) break else: print(-1)
s834217671
p03680
u891847179
1584925195
Python
Python (3.4.3)
py
Runtime Error
354
27872
570
import math from collections import defaultdict N = int(input()) a = defaultdict(list) for i in range(1, N + 1): a[int(input())].append(i) def check(key): # print(key) if key == 1: # find goal return 1 elif key == 2: # forming infinite loop return math.inf else: values = ...
s203648979
p03680
u655761160
1584917134
Python
Python (3.4.3)
py
Runtime Error
57
7836
280
import sys inputs = list(map(int, sys.stdin)) N = inputs[0] a = inputs[1:N] isFound = False ai = 1 for i in range(1, N + 1): ai = a[ai - 1] # print(f'a{i} = {ai}') if (ai == 2): isFound = True print(i) break if (isFound is False): print(-1)
s409626578
p03680
u655761160
1584916795
Python
Python (3.4.3)
py
Runtime Error
57
7836
277
import sys Input = list(map(int, sys.stdin)) N = Input[0] a = Input[1:N] isFound = False ai = 1 for i in range(1, N + 1): ai = a[ai - 1] # print(f'a{i} = {ai}') if (ai == 2): isFound = True print(i) break if (isFound is False): print(-1)
s176864389
p03680
u898967808
1584322776
Python
Python (3.4.3)
py
Runtime Error
18
2940
170
visited = [0]*n ans = 0 i = 0 while True: i = A[i] ans += 1 if visited[i]==1: ans = -1 break visited[i] = 1 if i == 1: break print(ans)
s615905591
p03680
u075595666
1584108517
Python
Python (3.4.3)
py
Runtime Error
17
3060
215
n = int(input()) for i in range(n): a.append(int(input())) t = [0] ans = 1 if t == 2: print(ans) else: while True: t = a[t-1] ans += 1 if t == 2: print(ans) break if ans > n: print('-1') break
s124560983
p03680
u170183831
1583894676
Python
Python (3.4.3)
py
Runtime Error
176
7208
237
n = int(input()) A = [int(input()) for _ in range(n)] used = {1} pos = 1 count = 0 for _ in range(n): pos = A[pos - 1] count += 1 if pos in used: print(-1) break used.append(pos) if pos == 2: print(count) break
s213480411
p03680
u078349616
1583646218
Python
Python (3.4.3)
py
Runtime Error
183
7084
133
N = int(input()) A = [int(input()) for _ in range(N)] nb = 0 for i in range(N): nb = A[nb] if nb == 2: print(i+1) exit()
s614255574
p03680
u757030836
1583199215
Python
Python (3.4.3)
py
Runtime Error
17
2940
174
N = int(input()) D = {i+1:int(input()) for i in range(N)} d = D{1} ans = 1 for i in range(N): if d==2: print(ans) exit() d = D[d] ans +=1 print(-1)
s134431859
p03680
u434872492
1581240973
Python
Python (3.4.3)
py
Runtime Error
250
17996
337
N = int(input()) a = [list() for i in range(N+1)] for i in range(N): b = int(input()) a[i+1].append(b) ans = 0 check = [] tmp = 1 check.append(tmp) flag = False while(1): tmp = a[tmp] ans += 1 if tmp==2: flag = True break if tmp in check: break if flag: print(ans) el...
s992755213
p03680
u314089899
1580087677
Python
Python (3.4.3)
py
Runtime Error
245
7904
407
#065b N = int(input()) a_list=[0] for i in range(N): ai = int(input()) a_list.append(ai) def push_button(pushed_button,pushed_button_set): if pushed_button == 2: print(len(pushed_button_set)) else: if pushed_button in pushed_button_set: print(-1) return -1 else: pushed_button_set.add(pushed_b...
s660532474
p03680
u686036872
1579899891
Python
Python (3.4.3)
py
Runtime Error
17
3060
212
N = str(input()) list=[] for i in range(N): list.append(int(input())) count=0 X=list[0] while True: X=list[X-1] count+=1 if X == 2: print(count+1) if count == 100000: print(-1)
s557802105
p03680
u843722521
1579456676
Python
PyPy3 (2.4.0)
py
Runtime Error
508
51676
145
n=int(input()) a=[(i,int(input())-1) for i in range(n)] c,x=0,0 for i in range(n): x=a[x] if x==2: print(i+1) break else: print(-1)
s082363274
p03680
u309141201
1579294238
Python
Python (3.4.3)
py
Runtime Error
208
9640
265
N = int(input()) a = [] for _ in range(N): a.append(int(input())) x = 1 visited = set([1]) answer = 0 while True: x = a[x] if x in visited: answer = -1 break visited.add(x) answer += 1 if x == 2: break print(answer)
s965860619
p03680
u309141201
1579293934
Python
Python (3.4.3)
py
Runtime Error
188
7084
340
N = int(input()) a = [] count = [1] answer = 1 for _ in range(N): a.append(int(input())) def search(A): answer += 1 if A in count or answer > N: # ループ処理 print(-1) exit() count.append(A) print(count) if A == 2: print(len(count) - 1) exit() search(a[A-1]) se...
s164501900
p03680
u309141201
1579293188
Python
Python (3.4.3)
py
Runtime Error
262
7932
320
N = int(input()) a = [] count = [1] answer = 0 for _ in range(N): a.append(int(input())) def search(A): if A in count: # ループ処理 print(-1) exit() count.append(A) # print(count) if A == 2: print(len(count) - 1) exit() search(a[A-1]) search(a[0])
s557857683
p03680
u241159583
1579236847
Python
Python (3.4.3)
py
Runtime Error
216
7084
213
N = int(input()) a = [int(input()) for _ in range(N)] n = 0 ans = 1 for _ in range(N): ans += 1 if a[a[n] - 1] == n + 1: ans = -1 break elif a[a[n] - 1] == 2: break n = a[a[n] - 1] print(ans)
s312162567
p03680
u492447501
1577639365
Python
Python (3.4.3)
py
Runtime Error
373
31000
520
N = int(input()) V = [] seen = [False]*N for _ in range(N): V.append(set()) index = 0 for _ in range(N): next_node = int(input()) V[index].add(next_node-1) index = index + 1 min = float('inf') def dfs(node, count): global min if seen[node]==True: return if node==1: if mi...
s968107251
p03680
u717265305
1577582862
Python
Python (3.4.3)
py
Runtime Error
2104
7084
316
n=int(input()) a = [int(input()) for _ in range(n)] position = a.index(2) if position == False: print(str(-1)) exit() position = position + 1 for i in range(n+1): # 最高でもn+!回だけ探してやれば十分 position = a.index(position) + 1 if position==1: print(str(i+2)) exit() print(str(-1))
s172668882
p03680
u717265305
1577582772
Python
Python (3.4.3)
py
Runtime Error
2104
7084
308
n=int(input()) a = [int(input()) for _ in range(n)] position = a.index(2) if position == False: print(-1) exit() position = position + 1 for i in range(n+1): # 最高でもn+!回だけ探してやれば十分 position = a.index(position) + 1 if position==1: print(i+2) exit() print(-1) exit()
s956454599
p03680
u717265305
1577582665
Python
Python (3.4.3)
py
Runtime Error
2104
7084
288
n=int(input()) a = [int(input()) for _ in range(n)] position = a.index(2) + 1 if position == False: print(-1) exit() for i in range(n+1): # 最高でもn+!回だけ探してやれば十分 position = a.index(position) + 1 if position==1: print(i+2) exit() print(-1) exit()
s088260084
p03680
u063073794
1577558685
Python
Python (3.4.3)
py
Runtime Error
17
3060
252
yandy N = int(input()) a = [int(input()) for i in range(N)] num = 0 now = 0 been = set() been.add(0) while now != 1: now = a[now] - 1 if now in been: num = -1 break else: been.add(now) num += 1 print(num)
s275257779
p03680
u071416928
1577125790
Python
Python (3.4.3)
py
Runtime Error
199
7084
177
n = int(input()) a = [int(input()) for _ in range(n)] i = 0 cnt = 0 while not i == 1: i = a[i] - 1 cnt += 1 if i >= n or cnt > 100000: exit("-1") print(cnt)
s074881067
p03680
u609814378
1576954362
Python
Python (3.4.3)
py
Runtime Error
22
3192
3
あ
s311016077
p03680
u836984617
1575674442
Python
Python (3.4.3)
py
Runtime Error
17
2940
355
#include <bits/stdc++.h> using namespace std; int main() { int N, btn; cin >> N; btn = 1; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } for (int i = 0; i < N; i++) { if (btn == 2) { cout << i << endl; break; } btn = a.at(btn - 1); } if (btn != ...
s153580308
p03680
u836984617
1575674377
Python
Python (3.4.3)
py
Runtime Error
17
2940
354
#include <bits/stdc++.h> using namespace std; int main() { int N, btn; cin >> N; btn = 1 vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } for (int i = 0; i < N; i++) { if (btn == 2) { cout << i << endl; break; } btn = a.at(btn - 1); } if (btn != 2...
s054849368
p03680
u753682919
1575003152
Python
Python (3.4.3)
py
Runtime Error
241
8808
232
#変数に注意。。。# def f(n,l): m=A[n] if m==1: print(l) elif L[m]==1: print(-1) else: L[m]=1 return f(m,l+1) N=int(input()) L=[0 for i in range(N)] A=[int(input())-1 for _ in range(N)] L[0]=1 f(0,1)
s168259911
p03680
u753682919
1575002636
Python
Python (3.4.3)
py
Runtime Error
242
8720
241
def f(n): m=A[n] if m==1: print(n) elif L[m]==1: print(-1) else: n+=1 L[m]=1 return f(m) N=int(input()) L=[0 for i in range(N)] A=[int(input())-1 for _ in range(N)] L[0]=1 n=0 if A[0]==1: print(1) else: f(0)
s387631388
p03680
u753682919
1575001852
Python
Python (3.4.3)
py
Runtime Error
241
8720
210
def f(n): m=A[n] if m==1: print(n) elif L[m]==1: print(-1) else: n+=1 L[m]=1 return f(m) N=int(input()) L=[0 for i in range(N)] A=[int(input())-1 for _ in range(N)] L[0]=1 n=0 f(0)
s042381380
p03680
u187109555
1574570275
Python
PyPy3 (2.4.0)
py
Runtime Error
579
58072
411
N = int(input()) light_rule = {n:int(input())-1 for n in range(N)} light = ["1"]+["0"]*(N-1) flag = 0 num = 0 bottun = 0 for _ in range(1e6): if light[1] == "1": flag = 1 break num += 1 # print(bottun, light_rule[bottun]) light[bottun] = "0" light[light_rule[bottun]] = "1" bott...
s921053423
p03680
u187109555
1574569939
Python
Python (3.4.3)
py
Runtime Error
227
17892
409
N = int(input()) light_rule = {n:int(input())-1 for n in range(N)} light = ["1"]+["0"]*(N-1) flag = 0 num = 0 bottun = 0 for _ in range(N): if light[2] == "1": flag = 1 break num += 1 # print(bottun, light_rule[bottun]) light[bottun] = "0" light[light_rule[bottun]] = "1" bottun...
s130354924
p03680
u187109555
1574569862
Python
PyPy3 (2.4.0)
py
Runtime Error
2124
336256
537
N = int(input()) light_rule = {n:int(input())-1 for n in range(N)} light = ["1"]+["0"]*(N-1) searched = {"".join(light):1} flag = 0 num = 0 bottun = 0 for _ in range(N): if light[2] == "1": flag = 1 break num += 1 # print(bottun, light_rule[bottun]) light[bottun] = "0" light[light_...
s318709607
p03680
u187109555
1574569765
Python
Python (3.4.3)
py
Runtime Error
2110
118496
537
N = int(input()) light_rule = {n:int(input())-1 for n in range(N)} light = ["1"]+["0"]*(N-1) searched = {"".join(light):1} flag = 0 num = 0 bottun = 0 for _ in range(N): if light[2] == "1": flag = 1 break num += 1 # print(bottun, light_rule[bottun]) light[bottun] = "0" light[light_...
s572565086
p03680
u175590965
1574472402
Python
Python (3.4.3)
py
Runtime Error
17
3060
166
n = int(input()) l = [int(input()-1 for i in range(n))] a = l[0] for i in range(n): if a == 1: print(i+1) exit() a = l[a] else: print(-1)
s729215565
p03680
u209619667
1574359107
Python
Python (3.4.3)
py
Runtime Error
189
7084
186
N = int(input()) A = [int(input()) for i in range(N)] Next = 0 for i in range(N): if Next == 2: Next = A[Next] p = i break; else: Next = A[Next-1] p = -1 print(p)
s371886379
p03680
u923659712
1574123081
Python
Python (3.4.3)
py
Runtime Error
17
3064
199
n=int(input()) s=[] k=s[0] ans=0 for i in range(n): a=int(input()) s.append(a) for j in range(n+1): if s[k]==2: ans+=1 print(ans) exit() else: ans+=1 k=s[s[k]] print(-1)
s888892762
p03680
u760794812
1573918265
Python
Python (3.4.3)
py
Runtime Error
249
17892
268
N = int(input()) dic = {} for i in range(N): a = int(input()) dic[i+1] = a counter = 0 place = 1 while place != 2: if dic[place] in dic: temp = dic[place] dic.pop(place) place = temp counter += 1 else: counter = -1 break print(counter)
s865819311
p03680
u638795007
1573706624
Python
PyPy3 (2.4.0)
py
Runtime Error
285
56624
1180
def bfs(n,e,fordfs): #点の数、スタートの点、有向グラフ W = [-1]*n #各点の状態量、最短距離とか,見たかどうかとか W[e] = 0 que = deque() que.append(e) len = [float("inf")]*n len[e] = 0 while que: now = que.popleft() nowv = W[now] nowlen = len[now] for ne in fordfs[now]: if nowv =...
s975465802
p03680
u754022296
1573231280
Python
Python (3.4.3)
py
Runtime Error
17
2940
194
n = int(input()) A = [ int(input()) for i in range(n) ] c = 0 temp = 1 s = {1} while temp not in s: temp = A[temp-1] c += 1 i temp == 2: print(c) exit() s.add(temp) print(-1)
s232641691
p03680
u182765930
1572746888
Python
Python (3.4.3)
py
Runtime Error
18
2940
51
n, m = map(int, input().split()) print((n-1)*(m-1))
s150599014
p03680
u314089899
1572397071
Python
Python (3.4.3)
py
Runtime Error
249
7972
513
#065b N = int(input()) a_list=[0] for i in range(N): ai = int(input()) a_list.append(ai) def push_button(pushed_button,ans): ans += 1 #print(ans,":",pushed_button,a_list[pushed_button]) if a_list[pushed_button] == 2: return ans elif a_list[pushed_button] == pushed_button or pu...
s318067155
p03680
u745385679
1572248864
Python
Python (3.4.3)
py
Runtime Error
190
7084
273
n = int(input()) a = [int(input()) for _ in range(n)] tmp = a[0] if a.index(2) == -1: print(-1) else: ans = -1 count = 0 for i in range(n): count += 1 if tmp == 2: ans = count break tmp = a[tmp - 1] print(ans)
s264155465
p03680
u745385679
1572248589
Python
Python (3.4.3)
py
Runtime Error
2104
7084
271
n = int(input()) a = [int(input()) for _ in range(n)] tmp = a[0] if a.index(2) == -1: print(-1) else: ans = -1 count = 0 while(tmp != 1): count += 1 if tmp == 2: ans = count break tmp = a[tmp - 1] print(ans)
s331443831
p03680
u874059570
1571884614
Python
Python (3.4.3)
py
Runtime Error
17
2940
322
N = int(input()) a_lis = [int(input()) for _ in range(N)] now = 1 flag = 1 memo = [] cnt = 0 for i in range(N) next = a_lis[now-1] if next in memo: print(-1) flag = 0 break else: memo.append(next) now = next cnt+=1 if next ==2: print(cnt) brea...
s927485828
p03680
u961674365
1571374741
Python
Python (3.4.3)
py
Runtime Error
17
2940
205
n=int(input()) ans=1 a=[] for i in range(n): a.append(int(input())) x=a[0] if x=-2: print(ans) exit() for i in range(n): x=a[x-1] if x==2: print(ans+1) exit() else: ans+=1 print(-1)
s205573236
p03680
u381246791
1570824366
Python
Python (3.4.3)
py
Runtime Error
55
7184
265
# -*- coding:utf-8 -*- import sys a=[int(i)-1 for i in sys.stdin] N=l[0]+1 a=a[1:] done=[False]*N ans=0 i=0 while True: if done[i]==False: done[i]=True ans+=1 if a[i]==1: break i=a[i] else: ans=-1 break print(ans)
s424550146
p03680
u381246791
1570822012
Python
Python (3.4.3)
py
Runtime Error
18
2940
279
# -*- coding:utf-8 -*- N=int(input()) button=[] for i in range(N): button.append(int(input())) number=0 count=0 footprint=[0] while number!=1: number=button[number]-1 count+=1 if number in footprint: print(-1) exit() footprint.append(number) print(count)
s557354311
p03680
u747602774
1570733976
Python
Python (3.4.3)
py
Runtime Error
184
7084
221
N=int(input()) li=[] for n in range(N): a=int(input()) li.append(a) s=0 count=0 while s!=1: if count==N: break else: check.append(s) s=li[s]-1 count+=1 if s==1: print(count) else: print(-1)
s891163360
p03680
u450904670
1570420165
Python
Python (3.4.3)
py
Runtime Error
248
16296
272
import sys sys.setrecursionlimit(10000) def search(arr, num, i): nxt = arr[num] if(nxt == 1): return i elif(i >= len(arr)): return -1 else: return search(arr, nxt, i+1) n = int(input()) a = [ int(input()) - 1 for _ in range(n)] print(search(a, 0, 1))
s550584600
p03680
u450904670
1570420118
Python
Python (3.4.3)
py
Runtime Error
18
3060
261
sys.setrecursionlimit(10000) def search(arr, num, i): nxt = arr[num] if(nxt == 1): return i elif(i >= len(arr)): return -1 else: return search(arr, nxt, i+1) n = int(input()) a = [ int(input()) - 1 for _ in range(n)] print(search(a, 0, 1))
s203149087
p03680
u450904670
1570418866
Python
Python (3.4.3)
py
Runtime Error
234
7984
232
def search(arr, num, i): nxt = arr[num] if(nxt == 1): return i elif(i >= len(arr)): return -1 else: return search(arr, nxt, i+1) n = int(input()) a = [ int(input()) - 1 for _ in range(n)] print(search(a, 0, 1))
s655857434
p03680
u450904670
1570418505
Python
Python (3.4.3)
py
Runtime Error
237
7984
224
def search(a, num, i): nxt = a[num] if(nxt == 1): return i elif(i >= len(a)): return -1 else: return search(a, nxt, i+1) n = int(input()) a = [ int(input()) - 1 for _ in range(n)] print(search(a, 0, 1))
s085895032
p03680
u450904670
1570418179
Python
Python (3.4.3)
py
Runtime Error
236
8040
222
def search(a, num, i): nxt = a[num] if(nxt == 1): return i elif(i >= len(a)): return -1 else: return search(a, nxt, i+1) n = int(input()) a = [ int(input())-1 for _ in range(n)] print(search(a, 0, 1))
s253199694
p03680
u554096168
1570061047
Python
Python (3.4.3)
py
Runtime Error
18
2940
323
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N, 0); for (int i; i < N; i++) { cin >> a[i]; } int ans = -1, tmp = 0; for (int i = 0; i < N; i++) { tmp = a[tmp] - 1; if (tmp == 1) { ans = i + 1; break; } } cout << ans << endl;...
s720837291
p03680
u202570162
1569554665
Python
Python (3.4.3)
py
Runtime Error
206
7084
534
n = int(input()) a = [int(input())-1 for i in range(n)] #ボタンを押す=listから値を取得して-1にする #取得した値=光っているボタンの番号 #光っているボタンの番号が1ならbreak #取得した値が-1なら2を通らずループしてしまっている sb = 0 ans = 0 for i in range(n): if sb == 1: flag = True break elif sb == -1: flag = False break tmp = a[sb] a[sb] = -1 ...
s207343291
p03680
u155687575
1568564650
Python
PyPy3 (2.4.0)
py
Runtime Error
504
50392
245
n = int(input()) alist = [int(input())-1 for _ in range(n)] now = 0 count = 0 while True: if now == 1: print(count) break elif c >= n: print(-1) break else: count += 1 now = alist[now]
s641730718
p03680
u155687575
1568564623
Python
Python (3.4.3)
py
Runtime Error
176
7084
247
n = int(input()) alist = [int(input())-1 for _ in range(n)] now = 0 count = 0 while True: if now == 1: print(coount) break elif c >= n: print(-1) break else: count += 1 now = alist[now]
s208630803
p03680
u155687575
1568564091
Python
PyPy3 (2.4.0)
py
Runtime Error
527
49240
241
n = int(input()) alist = [int(input())-1 for _ in range(n)] now = 0 count = 0 while True: if now == 1: print(c) break elif c >= n: print(-1) break else: count += 1 now = alist[now]
s737910115
p03680
u155687575
1568563386
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38384
309
n = int(input()) alist = [int(input())-1 for _ in range(n)] visitedlist = [0] from = 0 for _ in range(n): to = alist[from] if to in visitedlist: print(-1) break elif to == 1: print(len(visitedlist)) break else: visitedlist.append(to) from = to
s935417735
p03680
u580093517
1568434213
Python
Python (3.4.3)
py
Runtime Error
175
7084
126
a = [int(input()) for _ in range(int(input()))] c,s = 1,a[0] if s != 2 and c < n: c,s = c+1,a[n-1] print(c if c < n else "-1")
s329884870
p03680
u787456042
1568231319
Python
Python (3.4.3)
py
Runtime Error
62
7956
97
*A,=map(int,open(0));i=1;t=[0]*A[0] while i-2and t[i]==0:t[i]=1;i=A[i] print(-1if i-2else sum(t))
s302512705
p03680
u787456042
1568231176
Python
Python (3.4.3)
py
Runtime Error
2104
7828
93
*A,=map(int,open(0));i=1;t=[0]*A[0] while i-2or t[i]:t[i]=1;i=A[i] print(-1if i-2else sum(t))
s695545875
p03680
u787456042
1568231113
Python
Python (3.4.3)
py
Runtime Error
2104
7956
95
*A,=map(int,open(0));i=1;t=[0]*A[0] while i-2or i in t:t[i]=1;i=A[i] print(-1if i-2else sum(t))
s498105102
p03680
u893063840
1567815639
Python
Python (3.4.3)
py
Runtime Error
200
9640
254
n = int(input()) a = [int(input()) for _ in range(n)] pushed = set() cnt = 0 push= 1 while True: if push in pushed: cnt = -1 break pushed.add(push) push = a[push] cnt += 1 if push == 2: break print(cnt)