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
s149607648
p03680
u784341473
1567393033
Python
Python (3.4.3)
py
Runtime Error
232
7084
187
l=[int(input()) for _ in range(int(input()))] x=l[0] cnt=1 while l[x]!=2: if(l[x]==0 or len(l)==cnt): print(-1) exit() index=l[x] l[x]=0 x=int(index-1) cnt+=1 print(cnt)
s390954820
p03680
u677523557
1567262596
Python
Python (3.4.3)
py
Runtime Error
203
7852
308
N = int(input()) A = [int(input()) for _ in range(N)] c = 0 n = 1 checked = [False for _ in range(N)] checked[0] = True for _ in range(N+1): n = A[n-1] c += 1 if n == 2: ok = True break if checked[n-1]: ok = False break if ok: print(c) else: print(-1)
s037983955
p03680
u677523557
1567262485
Python
Python (3.4.3)
py
Runtime Error
204
7084
248
N = int(input()) A = [int(input()) for _ in range(N)] c = 0 n = 1 for _ in range(N+1): n = A[n-1] c += 1 if n == 1: ok = False break if n == 2: ok = True break if ok: print(c) else: print(-1)
s771248925
p03680
u835482198
1567118367
Python
Python (3.4.3)
py
Runtime Error
239
8808
437
n = int(input()) As = [int(input()) for _ in range(n)] visited = [-1 for i in range(n)] def rec(visited, i, depth): # print(i, visited[i]) if visited[i] > 0: return visited[i] elif visited[i] == 0: return -1 if As[i] == 2: visited[i] = 1 return depth visited[i] = 0 ...
s041007648
p03680
u835482198
1567118103
Python
Python (3.4.3)
py
Runtime Error
242
8812
466
n = int(input()) As = [int(input()) for _ in range(n)] visited = [-1 for i in range(n)] def rec(visited, prev_i, i, depth): if visited[i] >= 0: return visited[i] if As[i] == 2: visited[i] = 1 return depth if prev_i == As[i] - 1: visited[i] = 0 return visited[i] ...
s889253213
p03680
u835482198
1567118020
Python
Python (3.4.3)
py
Runtime Error
250
8804
415
n = int(input()) As = [int(input()) for _ in range(n)] visited = [-1 for i in range(n)] def rec(visited, prev_i, i, depth): if visited[i] > 0: return visited[i] if As[i] == 2: visited[i] = 1 return depth if prev_i == As[i] - 1: return visited[i] visited[i] = rec(visited...
s846999823
p03680
u967843578
1566929487
Python
Python (3.4.3)
py
Runtime Error
250
8076
306
#!/usr/bin/env python N = 1 a = [] def sol(x, cnt) : cnt+=1 if a[x-1] == 2 : return cnt if cnt > N : return -1 return sol(a[x-1], cnt) if __name__ == '__main__' : N = int(input()) for i in range(N) : a.append(int(input())) print( sol(1,0) )
s718775967
p03680
u762540523
1566342160
Python
Python (3.4.3)
py
Runtime Error
18
2940
266
def main(): n = int(input()) a =[] for n in range(n): a.append(int(input())-1) sw = [0] while True: nextsw = sw[-1] if nextsw = 1: print(len(sw)) return if nextsw in sw: print(-1) return sw.append(nextsw) main()
s604315715
p03680
u798316285
1565981686
Python
Python (3.4.3)
py
Runtime Error
187
7072
137
n=int(input()) A=list(int(input()) for i in range(n)) a=0 for x in range(n): a=A[i] if a==2: print(x) break else: print(-1)
s324497057
p03680
u798316285
1565981617
Python
Python (3.4.3)
py
Runtime Error
196
7072
119
n=int(input()) A=list(int(input()) for i in range(n)) a=0 for x in range(n): a=a[i] if a==2: print(x) break
s848500165
p03680
u371530330
1565922398
Python
Python (3.4.3)
py
Runtime Error
182
7084
213
n = int(input()) an = [int(input())-1 for i in range(n)] cnt = 0 x = 0 for i in range(n): if a[x] == 1: break elif a[x] != 1: x = a[x] cnt = cnt +1 if cnt > n: print(-1) else: print(cnt)
s048111172
p03680
u131634965
1565893509
Python
Python (3.4.3)
py
Runtime Error
205
7084
204
N=int(input()) a=[] for _ in range(N): a.append(int(input())) turn_on=a[0] for count in range(2,N): if a[turn_on]==2: print(count) exit() turn_on=a[turn_on-1] print(-1)
s578349068
p03680
u131634965
1565893466
Python
Python (3.4.3)
py
Runtime Error
202
7084
204
N=int(input()) a=[] for _ in range(N): a.append(int(input())) turn_on=a[0] for count in range(1,N): if a[turn_on]==2: print(count) exit() turn_on=a[turn_on-1] print(-1)
s287273600
p03680
u131634965
1565893438
Python
Python (3.4.3)
py
Runtime Error
215
7084
217
N=int(input()) a=[] for _ in range(N): a.append(int(input())) turn_on=a[0] for count in range(1,N): count+=1 if a[turn_on]==2: print(count) exit() turn_on=a[turn_on-1] print(-1)
s643855578
p03680
u219086885
1565884133
Python
Python (3.4.3)
py
Runtime Error
178
7084
147
n = int(input()) an = [int(input()) for i in range(n)] c, s = 1, a[0] while s != 2 and c < n: c, s = c + 1, a[s - 1] print(c if c < n else -1)
s131427244
p03680
u248670337
1565839121
Python
Python (3.4.3)
py
Runtime Error
171
7084
121
n=int(input()) a=[int(input()) for i in range(n)] c,s=1,a[0] while S!=2 and c<n: c,s=c+1,a[s-1] print(c if c<n else -1)
s245279326
p03680
u037221289
1565837766
Python
Python (3.4.3)
py
Runtime Error
17
3060
168
N = int(input()) list = [int(input()) for i in range(n)] c = 0 x = 1 while x != 2 and c < N: x = list[x - 1] c += 1 if x == 2: print(c) else: print(-1)
s700471938
p03680
u842388336
1565821384
Python
Python (3.4.3)
py
Runtime Error
194
7852
275
N = int(input()) b_list = [] for _ in range(N): b_list.append(int(input())) i = b_list[0] keiyu_list = [0 for _ in range(N)] cnt=0 while keiyu_list[i]==0: i = b_list[i-1] keiyu_list[i]=1 cnt+=1 if i == 2: cnt+1 break if i==2: print(cnt) else: print(-1)
s114695507
p03680
u469953228
1565590765
Python
Python (3.4.3)
py
Runtime Error
39
3060
175
n=int(input()) li=[int(i) for i in input().split()] x = li[0] ans = -1 count=0 for i in range(n): x = li[x-1] if x == 2: ans = count+1 break count +=1 print(ans)
s784894975
p03680
u797016134
1565064375
Python
Python (3.4.3)
py
Runtime Error
2108
138260
269
n = int(input()) a = [int(input()) for i in range(n)] on = 1 count = 0 on_li = [1] while True: on = a[on-1] if on in on_li: print(-1) exit() on_li.append(on) print(on_li) count += 1 if on == 2: print(count) exit()
s991270841
p03680
u408620326
1565062537
Python
Python (3.4.3)
py
Runtime Error
1799
140064
202
N=int(input()) aN=[int(input()) for _ in range(N)] c=0 i=1 while True: print(aN) c+=1 if aN[i-1]==2: print(c) break elif aN[i-1]==0: print(-1) break t=aN[i-1] aN[i-1]=0 i=t
s273489721
p03680
u408620326
1565061904
Python
Python (3.4.3)
py
Runtime Error
173
7084
165
N=int(input()) aN=[int(input()) for _ in range(N)] c=0 i=1 while True: c+=1 if a[i]==2: print(c) break elif a[i]==0: print(-1) i=a[i] a[i]=0
s292205332
p03680
u659100741
1564871752
Python
Python (3.4.3)
py
Runtime Error
2104
7724
290
n = int(input()) a = [int(input()) for i in range(n)] check = [] cnt = 0 i = 0 while True: if i not in check: check.append(i) i = a[i]-1 elif cnt >= len(n): print(-1) break if i == 1: print(len(check)) break cnt += 1
s225465336
p03680
u105124953
1564800445
Python
Python (3.4.3)
py
Runtime Error
401
99384
359
import sys sys.setrecursionlimit(100000) n = int(input()) a_list = [int(input()) for _ in range(n)] def calc_ans(start_num, count, max_count, all_list): ans = all_list[start_num-1] if ans == 2: print(count) elif count == max_count: print('-1') else: calc_ans(ans, count+1, max_cou...
s504287393
p03680
u105124953
1564800006
Python
Python (3.4.3)
py
Runtime Error
229
7980
306
n = int(input()) a_list = [int(input()) for _ in range(n)] def calc(start_num, count, max_count, all_list): ans = all_list[start_num-1] if ans == 2: print(count) elif count == max_count: print('-1') else: calc(ans, count+1, max_count, all_list) calc(1, 1, n, a_list)
s694514922
p03680
u105124953
1564799840
Python
Python (3.4.3)
py
Runtime Error
229
7980
306
n = int(input()) a_list = [int(input()) for _ in range(n)] def calc(start_num, count, max_count, all_list): ans = all_list[start_num-1] if ans == 2: print(count) elif count == max_count: print('-1') else: calc(ans, count+1, max_count, all_list) calc(1, 1, n, a_list)
s377380358
p03680
u536685012
1564722397
Python
Python (3.4.3)
py
Runtime Error
17
2940
1
a
s585787264
p03680
u536685012
1564722330
Python
Python (3.4.3)
py
Runtime Error
18
3064
177
N = int(input()) n = [] for i in range(N): n.append(int(input())) a = 1 c = -1 for i in range(N): a = n[a-1] if c != -1: if a == 2: c = (i+1) else: print(c)
s357444327
p03680
u736729525
1564718933
Python
Python (3.4.3)
py
Runtime Error
17
2940
191
N = int(input()) A = [0]+[int(input()) for _ in range(N)] v = {1} x = 1 a = 0 while True: x = A[x] a += 1 if x in v: print(-1) break if x == 2: print(a) break v.add(x)
s364782050
p03680
u736729525
1564718784
Python
Python (3.4.3)
py
Runtime Error
17
2940
180
N = int(input()) A = [0]+[int(input()) for _ in range(N)] v = {1} x = 1 a = 0 while True: x = A[x] a += 1 if x in v: print(-1) break if x == 2: print(a) break
s686063517
p03680
u759412327
1564429983
Python
Python (3.4.3)
py
Runtime Error
175
7884
238
N = int(input()) a = [0] + [int(input()) for _ in range(N)] 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)
s025026366
p03680
u897328029
1564148422
Python
Python (3.4.3)
py
Runtime Error
2104
27408
1231
# https://atcoder.jp/contests/abc065/tasks/abc065_b # B - Trained? n = int(input().split()[0]) index2number_dict = {} number2index_dict = {} for i in range(n): a_i = int(input().split()[0]) index2number_dict[i+1] = a_i number2index_dict[a_i] = i+1 # ボタンが光っているときに押すと、 # 今のボタンの光が消える # 次のボタンが光る # ボタン2が光っている状...
s240750040
p03680
u214434454
1563509094
Python
Python (3.4.3)
py
Runtime Error
174
7084
250
n = int(input()) a = [int(input()) for i in range(n)] count = 0 i = 0 ans = False while count < N: count += 1 if a[i] == 2: ans = True break else: i = a[i] - 1 if ans == True: print(count) else: print("-1")
s571146989
p03680
u790812284
1562991826
Python
Python (3.4.3)
py
Runtime Error
174
7084
215
import sys n=int(input()) a=[int(input()) for _ in range(n)] cnt=0 tmp=1 for i in range(n): cnt+=1 already.append(tmp) tmp=a[tmp-1] if tmp==2: print(cnt) sys.exit() print(-1)
s039811034
p03680
u790812284
1562991260
Python
Python (3.4.3)
py
Runtime Error
174
7084
306
n=int(input()) a=[int(input()) for _ in range(n)] for i in range(a): if a[i]==i+1: print(-1) cnt=0 tmp=1 already=[] while True: cnt+=1 already.append(tmp) tmp=a[tmp-1] if tmp==2: print(cnt) break elif tmp in already: print(-1) break
s287387218
p03680
u623687794
1561784176
Python
Python (3.4.3)
py
Runtime Error
170
7084
222
n=int(input()) button=[int(input()) for i in range(n)] temp=1 ans=1 while button[temp-1] not in check: temp=button[temp-1] ans+=1 if button[temp-1]==2: print(ans) break elif ans>=n: print(-1) break
s450053098
p03680
u623687794
1561783986
Python
Python (3.4.3)
py
Runtime Error
174
7084
224
n=int(input()) button=[int(input()) for i in range(n)] temp=1 ans=1 while button[temp-1] not in check: temp=button[temp-1] ans+=1 if button[temp-1]==2: print(ans) break elif ans>=n+1: print(-1) break
s145397779
p03680
u313402971
1561751146
Python
Python (3.4.3)
py
Runtime Error
172
7084
315
N = int(input()) buttons = [int(input()) for i in range(N)] pushed = list() button = 1 count = 0 while(True): button = buttons[button - 1] count +=1 if (button == 2): print(count) break elif(button in pushed): print(-1) break else: pushued.append(button)
s396787518
p03680
u908349502
1561404412
Python
Python (3.4.3)
py
Runtime Error
17
2940
273
=int(input()) a=[] for i in range(n): ai=int(input()) a.append(ai) finish=False for i in range(n): if i==0: next=a[a[0]-1] else: next=a[next-1] if next==2: print(i+2) finish=True break if not finish: print(-1)
s762609403
p03680
u780675733
1561151070
Python
Python (3.4.3)
py
Runtime Error
18
2940
241
phai = 1 cnt = 0 loop_hantei = {1} for _ in range(N): phai = A[phai-1] cnt += 1 if phai in loop_hantei: print('-1') break else: loop_hantei.add(phai) if phai == 2: print(cnt) break
s753616373
p03680
u932719058
1560842119
Python
Python (3.4.3)
py
Runtime Error
17
3188
255
n = int(input()) l = [] ans = 1 for _ in range(n) : l.append(int(input())) if l[0] == 2 : print(1) else : i = l[0] - 1 while True : if l[i] == 2 : ans += 1 break i = l[i] - 1 ans += 1 if ans == n+1 : print(-1) exit() print(ans)
s262928407
p03680
u932719058
1560841398
Python
Python (3.4.3)
py
Runtime Error
216
7084
244
n = int(input()) l = [] ans = 1 for _ in range(n) : l.append(int(input())) if l[0] == 2 : print(1) else : i = l[0] - 1 while True : if l[i] == 2 : ans += 1 break i = l[i] - 1 ans += 1 if ans == n+1 : print('-1') exit() print(ans)
s862988094
p03680
u062459048
1560699372
Python
Python (3.4.3)
py
Runtime Error
204
7084
209
n = int(input()) lista = [] for i in range(n): lista.append(int(input())) count = 1 fp = lista[0] for i in range(n): fp = lista[fp] count += 1 if fp == 2: print(count) exit() print(-1)
s333045933
p03680
u223904637
1560562938
Python
Python (3.4.3)
py
Runtime Error
212
7796
263
n=int(input()) l=[0]*n for i in range(n): l[i]=int(input()) vi=[0]*n vi[0]=1 ans=1 st=l[0] f=0 while vi[1]==0: vi[st]+=1 if vi[st]>1: f=1 break st=l[st-1] ans+=1 if f==0: print(ans) else: print(-1)
s960630224
p03680
u539517139
1560258478
Python
Python (3.4.3)
py
Runtime Error
17
2940
160
n=int(input()) a=[0]*n for _ in range(n): a[_]=int(input()) c=0 p=a[0] while True: p=a[p-1] c+=1 if p=2: break if p=1: c=-1 break print(c)
s377892663
p03680
u538632589
1560114094
Python
Python (3.4.3)
py
Runtime Error
2104
7456
312
N = int(input()) a = [int(input()) for i in range(N)] stack = [2] can = False while True: if stack[len(stack)-1] == 1: can = True break c = stack[len(stack)-1] i = a.index(c)+1 if i in stack: break stack.append(i) if can: print(len(stack)-1) else: print(-1)
s285593652
p03680
u172111219
1560048984
Python
PyPy3 (2.4.0)
py
Runtime Error
633
57312
246
n = int(input()) a = [int(input()) for _ in range(n)] def solve(a,index,l): if l == len(a)+1: return print(-1) value = a[index-1] if value == 2: return print(l) else: solve(a,value,l+1) solve(a,1,1)
s513895490
p03680
u172111219
1560048759
Python
PyPy3 (2.4.0)
py
Runtime Error
628
57816
270
n = int(input()) a = [int(input()) for _ in range(n)] index = a.index(1)+1 def solve(a,index,l): if l == len(a)+1: return print(-1) value = a[index-1] if value == 2: return print(l) else: solve(a,value,l+1) solve(a,index,0)
s718979892
p03680
u672494157
1560005770
Python
Python (3.4.3)
py
Runtime Error
2104
16436
802
import functools def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def solve(inputs): a = list(map(lambda x: int(x), inputs)) a[1] = -1 return wh(a, 2, 0, len(a)) def wh(a, search, count, N): counts = [] if search == 1: return count elif cou...
s220834454
p03680
u672494157
1560005548
Python
Python (3.4.3)
py
Runtime Error
2104
15956
749
import functools def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def solve(inputs): a = list(map(lambda x: int(x), inputs)) a[1] = -1 return wh(a, 2, 0) def wh(a, search, count): counts = [] if search == 1: return count for i, value in en...
s081188638
p03680
u129978636
1559675262
Python
Python (3.4.3)
py
Runtime Error
141
9488
213
a=[input() for _ in range(int(input()))] ans=1 c=a[0] if(c==2): print(ans) else: while(c!=2): ans+=1 c=a[c-1] if(ans>len(a)): print(-1) exit() print(ans)
s716033518
p03680
u802772880
1559436368
Python
Python (3.4.3)
py
Runtime Error
177
7320
160
n=int(input()) a=[int(input())-1 for _ in range(n)] ans=-1 l=0 for i in range(n): l=a[l] cnt[l]+=1 if l==1: ans=i+1 break print(ans)
s283961532
p03680
u689322583
1559358792
Python
Python (3.4.3)
py
Runtime Error
17
3060
271
#coding: utf-8 import sys N = int(sys.stdin) a = [] for i in range(N): a.append(int(sys.stdin)) start = 0 count = 0 for i in range(N): count += 1 next = a[start] if(next == 2): print(count) break start = next - 1 else: print(-1)
s232257548
p03680
u689322583
1559358703
Python
Python (3.4.3)
py
Runtime Error
17
3064
264
#coding: utf-8 import sys N = sys.stdin a = [] for i in range(N): a.append(int(input())) start = 0 count = 0 for i in range(N): count += 1 next = a[start] if(next == 2): print(count) break start = next - 1 else: print(-1)
s529937427
p03680
u689322583
1559358566
Python
Python (3.4.3)
py
Runtime Error
17
3064
274
#coding: utf-8 import sys N = map(int, sys.stdin) a = [] for i in range(N): a.append(int(input())) start = 0 count = 0 for i in range(N): count += 1 next = a[start] if(next == 2): print(count) break start = next - 1 else: print(-1)
s537070818
p03680
u689322583
1559358352
Python
Python (3.4.3)
py
Runtime Error
18
3060
269
#coding: utf-8 import sys N = int(sys.stdin) a = [] for i in range(N): a.append(int(input())) start = 0 count = 0 for i in range(N): count += 1 next = a[start] if(next == 2): print(count) break start = next - 1 else: print(-1)
s561718471
p03680
u382431597
1559186695
Python
Python (3.4.3)
py
Runtime Error
2104
7084
659
import sys def search_next(nextbutton : int) -> int: nextbutton = a.index(nextbutton) +1 return nextbutton n = int(input()) a = [int(input()) for i in range(n)] nextbutton = 2 count = 1 try : nextbutton = search_next(nextbutton) except: print(-1) sys.exit() #print(nextbutton,"first") for _ in ra...
s794195034
p03680
u382431597
1559186378
Python
Python (3.4.3)
py
Runtime Error
2104
7084
639
import sys def search_next(nextbutton : int) -> int: nextbutton = a.index(nextbutton) +1 return nextbutton n = int(input()) a = [int(input()) for i in range(n)] nextbutton = 2 count = 1 try : nextbutton = search_next(nextbutton) except: print(-1) sys.exit() #print(nextbutton,"first") while 1: ...
s320111395
p03680
u279229189
1558301521
Python
Python (3.4.3)
py
Runtime Error
196
7192
200
length = int(input()) data = ([int(input()) for i in range(length)]) cnt = 0 i = 1 v = 0 while v != 2: v = data[i] i = v if cnt >= data[0]: cnt = -1 break cnt += 1 print(cnt)
s852081555
p03680
u279229189
1558301427
Python
Python (3.4.3)
py
Runtime Error
187
7084
197
length = int(input()) data = ([int(input()) for i in range(length)]) cnt = 0 i = 1 v = 0 while v != 2: v = data[i] i = v cnt += 1 if cnt >= data[0]: cnt = -1 break print(cnt)
s870221806
p03680
u448354193
1557874892
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38256
337
import sys n=int(input()) a=[] f=[] has2=False for i in range(n): ai=int(input()) if ai==2: has2=True a.append(ai) f.append(False) if has2==False: print("-1") sys.exit() f[0]=True now=0 cnt=0 while True: if f[now]==True: print(-1) break if now==2: print(cnt) break f[now]=True n...
s983207706
p03680
u152671129
1557510305
Python
Python (3.4.3)
py
Runtime Error
38
3060
206
n = int(input()) a = list(map(int, input().split())) next = a[0] count = 1 for i in range(1,n): if next == 2: print(count) break next = a[next-1] count += 1 else: print(-1)
s096692886
p03680
u039360403
1557199282
Python
Python (3.4.3)
py
Runtime Error
2104
7748
188
n=int(input()) a=list(int(input()) for _ in range(n)) i=1 c=1 i=a[a.index(i)-1] while c!=n or i == 2: i=a[a.index(i)-1] print(i) c+=1 print(-1 if c==n+1 else c) print(c)
s995081349
p03680
u756388720
1556587397
Python
Python (3.4.3)
py
Runtime Error
235
8796
186
N = int(input()) a = [int(input()) for _ in range(N)] c = [0] * N def f(i, n): if a[n] == 2: return i if c[n] == 1: return -1 c[n] = 1 return f(i + 1, a[n] - 1) print(f(1, 0))
s432392239
p03680
u732870425
1556400458
Python
Python (3.4.3)
py
Runtime Error
191
7084
173
N = int(input()) a = [int(input()) for _ in range(N)] button = 0 for i in range(1,N+1): button = a[a[button]-1] if button == 2: print(i) else: print(-1)
s771496580
p03680
u732870425
1556400281
Python
Python (3.4.3)
py
Runtime Error
197
7084
171
N = int(input()) a = [int(input()) for _ in range(N)] button = 0 for i in range(1,N+1): button = a[a[button]] if button == 2: print(i) else: print(-1)
s917334827
p03680
u220345792
1555857135
Python
Python (3.4.3)
py
Runtime Error
209
7084
237
N = int(input()) a = [] for i in range(N): a.append(int(input())) j = 0 count = 0 flag = False for i in range(N): if a[j] == 2: flag = True break else: j = a[j] count += 1 if flag: print(count) else: print(-1)
s636544424
p03680
u037430802
1555595424
Python
Python (3.4.3)
py
Runtime Error
17
2940
323
n = int(input()) arr = [] passed = [] for i in range(n): a = int(input()) arr.append(a) next_position = 1 ans = 0 while(1): next_position = arr[next_position-1] #print(position) if ans == n print(-1) break #passed.append(next_position) ans += 1 if next_position == 2: print(ans) break...
s455081711
p03680
u655975843
1555024935
Python
Python (3.4.3)
py
Runtime Error
120
7084
357
import sys ns = lambda: sys.stdin.readline().rstrip() ni = lambda: int(ns()) nm = lambda: map(int, sys.stdin.readline().split()) nl = lambda: list(nm()) n = ni() a = [ni() for _ in range(n)] count = 0 nexti = 0 for i in range(n): if nexti == 1: print(count) exit() else: nexti = a[a[nex...
s380169495
p03680
u300269535
1554992562
Python
Python (3.4.3)
py
Runtime Error
231
7992
477
count = 0 def judge(a, i): global count count += 1 if count > len(a): return -1 else: if 0 <= i < len(a): if a[i] == 2: return count else: return judge(a, a[i]-1) else: return -1 def B_Trained(): n = int(in...
s293968344
p03680
u300269535
1554992109
Python
Python (3.4.3)
py
Runtime Error
240
7992
425
count = 0 def judge(a, i): global count count += 1 if count > len(a): return -1 else: if a[i] == 2: return count else: return judge(a, a[i]-1) def B_Trained(): n = int(input()) a = [] for i in range(n): a.append(int(input())) ...
s494352441
p03680
u268516119
1554918530
Python
Python (3.4.3)
py
Runtime Error
519
11252
291
import sys sys.setrecursionlimit(5000) N=int(input()) A=[int(input())-1 for _ in range(N)] result=[] app=result.append def next(k): newlight=A[k] if k==1: return(1) elif k in result: return(0) else: app(k) return(next(newlight)) if not next(0): print(-1) else:print(len(result))
s768621673
p03680
u268516119
1554918444
Python
Python (3.4.3)
py
Runtime Error
293
11300
269
N=int(input()) A=[int(input())-1 for _ in range(N)] result=[] app=result.append def next(k): print(result,k) newlight=A[k] if k==1: return(1) elif k in result: return(0) else: app(k) return(next(newlight)) if not next(0): print(-1) else:print(len(result))
s521040726
p03680
u859897687
1554227822
Python
Python (3.4.3)
py
Runtime Error
182
7084
178
n=int(input()) d=[int(input())-1for i in range(n)] s=set(0) ans=0 b=0 while 1>0: if d[b] in s: ans=-1 break b=d[b] s.add(b) ans+=1 if b==1: break print(ans)
s495365851
p03680
u859897687
1554227785
Python
Python (3.4.3)
py
Runtime Error
176
7084
177
n=int(input()) d=[int(input())-1for i in range(n)] s=set(0) ans=0 b=0 while 1>0: if d[b] in s: ans=-1 break b=d[b] s+=d[b] ans+=1 if b==1: break print(ans)
s402588918
p03680
u878138257
1553841117
Python
Python (3.4.3)
py
Runtime Error
189
7084
218
n = int(input()) listA = [int(input()) for i in range(n)] a = listA[0] b = 0 for j in range(n): if a != 2: a = listA[a] b = b+1 elif a == 2: b = b+1 break if b == n: print(-1) else: print(b)
s716737687
p03680
u549497563
1553709929
Python
Python (3.4.3)
py
Runtime Error
17
2940
191
n = int(input()) a = [int(input()) for i in range(n)] i = 0 cnt = 1 while a[i]!=2: if i == a[a[i]-1]-1: print(-1) exit() i=a[i]-1 cnt += 1 else: print(cnt)
s117391559
p03680
u227082700
1553624576
Python
Python (3.4.3)
py
Runtime Error
18
3060
142
n,a,b,m=int(input()),[int(input())for i in range(n)],[],1 while m!=2 and m in b: b.append(m) m=b[m-1] if m==2:print(len(b)) else:print(-1)
s815874156
p03680
u280512618
1552970873
Python
Python (3.4.3)
py
Runtime Error
2104
7084
186
n = int(input()) a = [int(input()) for _ in range(n)] i = 1 c = 0 while True: if i == 2: print(c) quit(0) if a[i] == i: print(-1) quit(0) c += 1 i, a[i] = a[i], i
s821600240
p03680
u280512618
1552970756
Python
Python (3.4.3)
py
Runtime Error
2104
7084
159
n = int(input()) a = [int(input()) for _ in range(n)] i = 1 c = 0 while a[i] != i: if i == 2: print(c) quit(0) c += 1 i, a[i] = a[i], i print(-1)
s699070204
p03680
u952022797
1552340363
Python
Python (3.4.3)
py
Runtime Error
17
2940
355
# -*- coding: utf-8 -*- import sys def main(): N = int(input()) btnList = [] for _ in range(N): tmp = int(input()) btnList.append(tmp) tugi = btnList[0] i = 1 if tugi-1 == 1: print(i) sys.exit() while i < N+1: i += 1 tugi = btnList[tugi-1] if tugi-1 == 1: print(i) sys.exit() print(-1) i...
s667430006
p03680
u952022797
1552339548
Python
Python (3.4.3)
py
Runtime Error
17
2940
241
N = int(input()) ai = [int(input()) for i in range(N)] now = 1 count = 0 for i in range(N): count = count + 1 now = ai[now-1] if now == 2: print(count) exit() print(-1)
s663937825
p03680
u952022797
1552337341
Python
Python (3.4.3)
py
Runtime Error
2104
138572
397
# -*- coding: utf-8 -*- import sys def main(): N = int(input()) btnList = [] for _ in range(N): tmp = int(input()) btnList.append(tmp) tugi = btnList[0] lists = [0] while True: lists.append(tugi-1) tugi = btnList[tugi-1] print(lists) if tugi-1 == 1: print(len(lists)) sys.exit() if (tugi-1...
s593255501
p03680
u102960641
1552186373
Python
Python (3.4.3)
py
Runtime Error
188
7084
172
n = int(input()) a = [int(input()) for i in range(n)] now = 0 ans = -1 for i in range(n): value = a[now] if value == 2: ans = i+1 break now = value print(ans)
s605764337
p03680
u409064224
1551993703
Python
Python (3.4.3)
py
Runtime Error
1504
8076
385
n = int(input()) l = [] for i in range(n): l.append(int(input())) zero = l[0] count = 1 th = [zero] def r(index,throw): global l now = l[index-1] # print(now,throw) if (now in throw) or (2 not in l): print(-1) return if now != 2: throw.append(now) r(now,throw) ...
s856473690
p03680
u393512980
1551929953
Python
Python (3.4.3)
py
Runtime Error
18
3064
285
from collections import defaultdict N = int(input()) btn = [int(input()) for _ in range(N)] i, ans = 0, 0 checked = defaultdict(int) while 1: next = btn[i] ans += 1 if next == 2: print(ans) break if checked[next] == 1: print(-1) break i = next checked[i] = 1
s857384121
p03680
u906651641
1551845967
Python
Python (3.4.3)
py
Runtime Error
18
2940
191
n = int(input()) a = [int(input()) - 1 for i in range(n)] i = 0 count = 0 while(1): i = a[i] count += 1 if i == 1: break elif i == 0: print(-1) return 0 print(count)
s880774337
p03680
u796942881
1551148721
Python
Python (3.4.3)
py
Runtime Error
70
8616
289
import sys l = [int(i) for i in sys.stdin] N = l[0] a = l[1:] done = [False] * N i = 0 ans = 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)
s991958778
p03680
u013408661
1550676526
Python
Python (3.4.3)
py
Runtime Error
2104
7084
258
n=int(input()) lamp=[] status=1 count=0 possible=1 for i in range(n): p=int(input()) lamp.append(p) while status!=2 or count==n: status=lamp[status] count+=1 if count==n and status!=2: possible=0 if possible==1: print(count) else: print(-1)
s658453463
p03680
u543954314
1550635174
Python
Python (3.4.3)
py
Runtime Error
2104
7084
209
n = int(input()) a = [int(input()) for i in range(n)] c = 0 p = 0 while True: c = a[c] p += 1 if c == 1: print(p) exit() elif c == 0 and p > 1: print(-1) exit()
s358733144
p03680
u543954314
1550635056
Python
Python (3.4.3)
py
Runtime Error
172
7084
209
n = int(input()) a = [int(input()) for i in range(n)] c = 0 p = 0 while True: c = s[c] p += 1 if c == 1: print(p) exit() elif c == 0 and p > 1: print(-1) exit()
s855177608
p03680
u076503518
1550549747
Python
Python (3.4.3)
py
Runtime Error
243
7984
208
N = int(input()) a = [] for _ in [0]*N: a.append(int(input())) def solve(i, n): if n == 2: print(i) elif i == N: print(-1) else: return solve(i+1, a[n-1]) solve(0, 1)
s776809592
p03680
u023229441
1550191299
Python
Python (3.4.3)
py
Runtime Error
204
7084
168
n=int(input()) A=[] for i in range(n): A.append(int(input())) a=0 ans=1 for i in range(100100): if A[a]==1: print(ans) exit() ans+=1 a=A[a] print(-1)
s330092290
p03680
u931462344
1549255285
Python
Python (3.4.3)
py
Runtime Error
213
7084
186
n = int(input()) a = [] for i in range(n): a.append(int(input())) cnt = 0 t = 1 for i in a: t = a[t-1] cnt += 1 if t == 2: print(cnt) exit(1) print("-1")
s260291590
p03680
u931462344
1549255217
Python
Python (3.4.3)
py
Runtime Error
217
7084
184
n = int(input()) a = [] for i in range(n): a.append(int(input())) cnt = 0 t = 1 for i in a: t = a[t-1] cnt += 1 if t == 2: print(cnt) exit(1) print(-1)
s311445938
p03680
u089032001
1546747976
Python
Python (3.4.3)
py
Runtime Error
240
8920
275
def func(i=0, ans=0): if B[i] is True: return -1 else: B[i] = True ans += 1 if A[i] != 1: return func(A[i], ans) else: return ans n = int(input()) A = [int(input())-1 for i in range(n)] B = [False] * n print(func())
s177356751
p03680
u371467115
1546275145
Python
Python (3.4.3)
py
Runtime Error
17
2940
153
n=int(input()) a=[i+1:int(input()) for i in range(n)] v=1 for c in range(n): v=a[v] if v==2: print(c+1) break else: print(-1)
s736302197
p03680
u845427284
1546233598
Python
Python (3.4.3)
py
Runtime Error
2104
7084
179
n = int(input()) a =[] for i in range(n): a.append(int(input())) num = 0 count = 1 while num != 2: num = a[num] count += 1 if count >= n: count = -1 print(count)
s019484523
p03680
u845427284
1546233356
Python
Python (3.4.3)
py
Runtime Error
2104
7084
181
n = int(input()) a =[] for i in range(n): a.append(int(input())) num = 0 count = 0 while num != 2: count += 1 num = a[num] if count >= n: count = -1 print(count)
s456203156
p03680
u586478468
1546137951
Python
Python (3.4.3)
py
Runtime Error
212
7084
310
N = int(input()) A = [] for i in range(N): A.append(int(input())) count=1 num=0 ans = A.index(2) st = A[0] for i in range(N): if(A[0] == 2): print(count) break count+=1 if(st==ans+1): print(count) num=1 break st = A[st-1] if(num!=1): print(-1)