problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p02683
|
u968649733
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
['#N, M, X = [int(n) for n in input().split()]\n\n#CA = [list(map(int, input().split())) for n in range(N)]\n\n#print(N,M,X)\n#print(CA)\n\nmin_cost = 12*10**5\n\n\ndef dfs(CA, cost, skills, cur, used, min_cost):\n #Pdb().set_trace()\n #print(cur)\n skills = [skills[i] + n for i, n in enumerate(CA[cur][1:])]\n used += [cur]\n cost += CA[cur][0]\n \n if all([s >= X for s in skills]):\n \treturn cost\n else:\n candidates = [n for n in range(N) if n not in used]\n prev_used = used\n prev_skills = skills\n prev_cost = cost\n for i in candidates:\n min_cost = min(min_cost, dfs(CA, prev_cost, prev_skills, i, prev_used, min_cost))\n return min_cost\n \n\nfor i in range(N):\n Pdb().set_trace()\n used = []\n cost = 0\n skills = [0] * M\n min_cost = min(min_cost, dfs(CA, cost, skills, i, used, min_cost)) \n\nprint(min_cost)', 'N, M, X = [int(n) for n in input().split()]\n\nCA = [list(map(int, input().split())) for n in range(N)]\n\nans = 10**10\n\nfor i in range(2**N):\n cost = 0\n skills = [0] * M\n for j in range(N):\n if ((i >> j) & 1):\n #print(i, j)\n for k in range(M):\n skills[k] += CA[j][1+k]\n cost += CA[j][0]\n \n if all([n >= X for n in skills]):\n \tans = min(ans, cost)\n #print("ans", ans)\nif ans == 10**10:\n print(-1)\nelse:\n print(ans)']
|
['Runtime Error', 'Accepted']
|
['s860758034', 's133292758']
|
[9168.0, 9228.0]
|
[25.0, 87.0]
|
[829, 468]
|
p02683
|
u970082363
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
['n,k,x = (int(x) for x in input().split())\nC = []\nA = []\nfor i in range(n):\n list = [int(i) for i in input().split()]\n C.append(list[0])\n A.append(list[1:])\ni = 0\ncase = [0]*(2**n)\nchk = []\nfor i in range(2**n):\n chk.append([0]*m)\ni = 0\nfor i in range(2 ** n):\n for j in range(n): \n if ((i >> j) & 1): \n case[i] += C[j]\n for l in range(m):\n chk[i][l] += A[j][l]\ni = 0\nj = 0\nans = []\nflag = [True]*(2**n)\nfor i in range(2**n):\n for j in range(m):\n if chk[i][j]<x:\n flag[i] = False\n if flag[i]:\n ans.append(case[i])\n\nif ans==[]:\n print(-1)\nelse:\n print(min(ans))\n', 'n,k,x = (int(x) for x in input().split())\nC = []\nA = []\nfor i in range(n):\n list = [int(i) for i in input().split()]\n C.append(list[0])\n A.append(list[1:])\ncase = [0]*(2**n)\nchk = []\nfor i in range(2**n):\n chk.append([0]*m)\n\nfor i in range(2 ** n):\n for j in range(n): \n if ((i >> j) & 1): \n case[i] += C[j]\n for l in range(m):\n chk[i][l] += A[j][l]\n\nans = []\nflag = [True]*(2**n)\nfor i in range(2**n):\n for j in range(m):\n if chk[i][j]<x:\n flag[i] = False\n if flag[i]:\n ans.append(case[i])\n\nif ans==[]:\n print(-1)\nelse:\n print(min(ans))', 'n,k,x = (int(x) for x in input().split())\nC = []\nA = []\nfor i in range(n):\n list = [int(i) for i in input().split()]\n C.append(list[0])\n A.append(list[1:])\ncase = [0]*(2**n)\nchk = []\nfor i in range(2**n):\n chk.append([0]*m)\n\nfor i in range(2 ** n):\n for j in range(n): \n if ((i >> j) & 1): \n case[i] += C[j]\n for l in range(m):\n chk[i][l] += A[j][l]\n\nans = []\nflag = [True]*(2**n)\nfor i in range(2**n):\n for j in range(m):\n if chk[i][j]<x:\n flag[i] = False\n if flag[i]:\n ans.append(case[i])\n\nif ans==[]:\n print(-1)\nelse:\n print(min(ans))\n', 'n,m,x = (int(x) for x in input().split())\nC = []\nA = []\nfor i in range(n):\n list = [int(i) for i in input().split()]\n C.append(list[0])\n A.append(list[1:])\ni = 0\ncase = [0]*(2**n)\nchk = []\nfor i in range(2**n):\n chk.append([0]*m)\ni = 0\nfor i in range(2 ** n):\n for j in range(n):\n if ((i >> j) & 1):\n case[i] += C[j]\n for l in range(m):\n chk[i][l] += A[j][l]\ni = 0\nj = 0\nans = []\nflag = [True]*(2**n)\nfor i in range(2**n):\n for j in range(m):\n if chk[i][j]<x:\n flag[i] = False\n if flag[i]:\n ans.append(case[i])\n\nif ans==[]:\n print(-1)\nelse:\n print(min(ans))\n']
|
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s386204895', 's906795015', 's910935060', 's642935943']
|
[9272.0, 9284.0, 9208.0, 11228.0]
|
[24.0, 26.0, 21.0, 97.0]
|
[764, 741, 636, 654]
|
p02683
|
u970267139
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
["n, m, x = map(int, input().split())\nbook = [list(map(int, input().split())) for _ in range(n)]\nchoose = 1\ncost_min = 1000000 * n\nfor i in range(2 ** n - 1):\n a_list = [0] * (m + 1)\n c = bin(choose)[2:].zfill(n)\n for j in range(n):\n if c[n - j - 1] == '1':\n a_list = [x + y for (x, y) in zip(a_list, book[j])]\n choose += 1\n print(a_list)\n for k in a_list:\n if k < x:\n break\n else:\n cost = a_list[0]\n cost_min = min(cost_min, cost)\nprint(cost_min)", "n, m, x = map(int, input().split())\nbook = [list(map(int, input().split())) for _ in range(n)]\nchoose = 1\ncost_min = 10000000 * n\nfor i in range(2 ** n - 1):\n a_list = [0] * (m + 1)\n c = bin(choose)[2:].zfill(n)\n\n for j in range(n):\n if c[n - j - 1] == '1':\n a_list = [a + b for (a, b) in zip(a_list, book[j])]\n choose += 1\n \n for k in a_list[1:]:\n if k < x:\n break\n else:\n cost_min = min(cost_min, a_list[0])\n\nif cost_min != 10000000 * n:\n print(cost_min)\nelse:\n print(-1)"]
|
['Wrong Answer', 'Accepted']
|
['s972936298', 's992059394']
|
[9172.0, 9172.0]
|
[64.0, 62.0]
|
[516, 543]
|
p02683
|
u972658925
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
['n,m,x = map(int,input().split())\n\nlst = []\nfor _ in range(n):\n lst.append(list(map(int,input().split())))\n\nlst.sort(key=lambda x: sum(x[1:]) ,reverse=True)\n\nrikaido = [0]*m\nrikaido_check1 = [0]*m\n\nrikaido2 = [0]*m\nrikaido_check2 = [0]*m\n\nans1 = 0\nans2 = 0\n\ncheck1 = 0\nfor i in lst:\n for j in range(m):\n rikaido[j] += i[j+1]\n if rikaido[j] >= x:\n rikaido_check1[j] = 1\n ans1 += i[0]\n if sum(rikaido_check1) == m:\n check1 = 1\n break\n\nlst.sort(key=lambda x: x[0])\n\ncheck2 = 0\nfor i in lst:\n for j in range(m):\n rikaido2[j] += i[j+1]\n if rikaido2[j] >= x:\n rikaido_check2[j] = 1\n ans2 += i[0]\n if sum(rikaido_check2) == m:\n check2 = 1\n break\nprint(lst)\nif check1 == check2 == 0:\n print("-1")\nelse:\n print(min(ans1,ans2))', 'n,m,x = map(int,input().split())\nc_lst = [0]*n\na_lst = [0]*n \nfor i in range(n):\n lst = list(map(int,input().split()))\n c_lst[i] = lst[0]\n a_lst[i] = lst[1:]\n\nryoukin = float("inf")\n\nfor i in range(2**n):\n temporary = 0\n rikaido = [0]*m\n for j in range(n):\n if i&(1<<j):\n temporary += c_lst[j]\n for k in range(m):\n rikaido[k] += a_lst[j][k]\n \n for j in rikaido:\n if j >= x:\n continue\n else:\n break \n else:\n if temporary < ryoukin:\n ryoukin = temporary\n\nif ryoukin != float("inf"):\n print(ryoukin)\nelse:\n print("-1")']
|
['Wrong Answer', 'Accepted']
|
['s947443830', 's568371284']
|
[9272.0, 9224.0]
|
[22.0, 73.0]
|
[821, 763]
|
p02683
|
u975445930
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
["n,m,x = map(int, input().split())\nl = [list(map(int, input().split())) for i in range(n)]\nans = float('inf')\n\nfor i in range(2**n):\n sum = [0]*(M+1)\n \n for j in range(n):\n \n if ((i >> j) & 1):\n for k in range(M+1):\n sum[k] += l[j][k]\n if sum[0] < ans:\n for a in range(1,m+1):\n if sum[a] < x:\n break\n else:\n ans = sum[0]\nif ans == float('inf'):\n print(-1)\nelse:\n print(ans)", "n,m,x = map(int, input().split())\nl = [list(map(int, input().split())) for i in range(n)]\nans = float('inf')\n\nfor i in range(2**n):\n sum = [0]*(m+1)\n \n for j in range(n):\n \n if (i >> j) & 1:\n for k in range(m+1):\n sum[k] += l[j][k]\n if sum[0] < ans:\n for a in range(1,m+1):\n if sum[a] < x:\n break\n else:\n ans = sum[0]\nif ans == float('inf'):\n print(-1)\nelse:\n print(ans)"]
|
['Runtime Error', 'Accepted']
|
['s387222472', 's107054605']
|
[9228.0, 9180.0]
|
[25.0, 85.0]
|
[547, 537]
|
p02683
|
u981418135
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
['n,m,x = map(int, input().split())\nc_a = []\nfor i in range(n):\n c_a.append(list(map(int, input().split())))\n\nmin_sum_answer = 0\nfor i in range(n**2):\n min_sum = 0\n get_score = []\n for m in range(m):\n get_score.append(0) \n for j in range(n):\n if i >> j % 2 ==1:\n mun_sum += c_a[j][0]\n for l in range(m):\n get_score[l] += c_a[j][l+1]\n \n pre = 0 \n for s in range(m):\n if(get_score[s} < x):\n pre = 1\n break\n \n if pre == 0:\n if min_sum_answer == 0:\n min_sum_answer = min_sum \n elif min_sum_answer > min_sum:\n min_sum_answer = min_sum \n\nif min_sum_answer == 0:\n print(-1)\nelse:\n print(min_sum_answer)', 'n,m,x = map(int, input().split())\nc_a = []\nfor i in range(n):\n c_a.append(list(map(int, input().split())))\n\nmin_sum_answer = -1\nfor i in range(2**n):\n min_sum = 0\n get_score = []\n for v in range(m):\n get_score.append(0) \n for j in range(n):\n if (i >> j) & 1 ==1:\n min_sum += c_a[j][0]\n for l in range(m):\n get_score[l] += c_a[j][l+1]\n \n #print(i)\n #print(min_sum)\n pre = 0 \n for s in range(m):\n if(get_score[s] < x):\n pre = 1\n break\n \n if pre == 0:\n if min_sum_answer == -1:\n min_sum_answer = min_sum \n elif min_sum_answer > min_sum:\n min_sum_answer = min_sum \n\nif min_sum_answer == 0:\n print(-1)\nelse:\n print(min_sum_answer)\n \n ']
|
['Runtime Error', 'Accepted']
|
['s036184621', 's738101284']
|
[9036.0, 9020.0]
|
[28.0, 100.0]
|
[837, 905]
|
p02683
|
u988661952
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
['import itertools\nimport numpy as np\nN,M,X=map(int,input().split())\nlista=[]\nfor i in range(N):\n lista.append(list(map(int,input().split())))\nlista=np.array(lista)\ncost=1000000000000000\njudge=[X]*M\ndata=[k for k in range(1,N+1)]\nfor i in range(1,N+1):\n a=list(itertools.combinations(data,i))\n for j in a:\n clist=np.array([0]*(M+1))\n for k in j:\n clist=clist+lista[k-1]\n if all(clist[1:]>=judge):\n if clist[0]<cost:\n cost=clist[0]\n m=j\nc=0\nfor i in m:\n c+=lista[i][0]\n\nprint(c) ', 'import itertools\nimport numpy as np\nN,M,X=map(int,input().split())\nlista=[]\nfor i in range(N):\n lista.append(list(map(int,input().split())))\nlista=np.array(lista)\ncost=1000000000000000\njudge=[X]*M\ndata=[k for k in range(1,N+1)]\nfor i in range(1,N+1):\n a=list(itertools.combinations(data,i))\n for j in a:\n clist=np.array([0]*(M+1))\n for k in j:\n clist=clist+lista[k-1]\n if all(clist[1:]>=judge):\n if clist[0]<cost:\n cost=clist[0]\n m=j\nc=0\ntry:\n for i in m:\n c+=lista[i-1][0]\n\n print(c)\nexcept:\n print(-1) ']
|
['Runtime Error', 'Accepted']
|
['s789665929', 's066176045']
|
[27680.0, 27684.0]
|
[147.0, 146.0]
|
[564, 602]
|
p02683
|
u989345508
| 2,000 | 1,048,576 |
Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.
|
['import itertools\n\nN, M, X = list(map(int, input().split()))\na = [list( map( int, input().split() ) ) for i in range(N)]\n\nfor x in itertools.product([0,1], repeat=2):\n cost = 0\n level = [] * M\n judge = True\n ans = 1234567\n for i in range(N):\n if a[i] == 1:\n cost += a[i][0]\n level = [y + z for (y, z) in zip(level, a[i][1:])]\n for j in range(M):\n if any(level[k] < x for k in range(M)):\n judge = False\n if judge:\n ans = min(ans, cost)\n\nif ans == 1234567:\n print(-1)\nelse:\n print(ans)', 'from itertools import product\nn,m,x=map(int,input().split())\nca=[list(map(int,input().split())) for i in range(n)]\nans=100000000000000000\nfor i in product([0,1],repeat=n):\n check=[0]*m\n ans_=0\n for j in range(n):\n if i[j]:\n \n ans_+=ca[j][0]\n for k in range(m):\n check[k]+=ca[j][k+1]\n if all([l>=x for l in check]):\n ans=min(ans,ans_)\nif ans==100000000000000000:\n print(-1)\nelse:\n print(ans)']
|
['Runtime Error', 'Accepted']
|
['s068162644', 's002929034']
|
[9208.0, 9100.0]
|
[25.0, 85.0]
|
[515, 479]
|
p02684
|
u010090035
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\na=list(map(int,input().split()))\nroop=[]\n\na.insert(0, 0)\ns=1\nfor i in range(k):\n s=a[s]\n if(s not in roop):\n roop.append(s)\n else:\n s_first=roop.index(s)\n roop=roop[s_first:]\n k-=(s_first+1)\n# print(k,roop,s_first)\n# print(roop[k%len(roop)])\n break\n', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\nroop=[]\nroop_set=set([])\n\na.insert(0, 0)\ns=1\nfor i in range(k):\n s=a[s]\n if(s not in roop_set):\n roop.append(s)\n roop_set.add(s)\n else:\n s_first=roop.index(s)\n roop=roop[s_first:]\n k-=(s_first+1)\n# print(k,roop,s_first)\n print(roop[k%len(roop)])\n break\nelse:\n# print(roop,k)\n print(roop[k-1])']
|
['Wrong Answer', 'Accepted']
|
['s694060659', 's849471397']
|
[32380.0, 32276.0]
|
[2206.0, 149.0]
|
[336, 425]
|
p02684
|
u010870870
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import sys\nN,K = map(int,input().split())\ntele = list(map(int,input().split()))\nk = 1\ngoal = tele[0]\nmiti = [1]\nwhile (goal in miti)!=1:\n k += 1\n miti.append(goal)\n goal = tele[goal-1]\n if k == K:\n goal = tele[goal-1]\n print(goal)\n sys.exit()\nprint(miti)\n\na = miti.index(goal)\nloop = k-a\nans = miti[(K-a)%loop+a]\n\nprint(ans)\n', 'import sys\nN,K = map(int,input().split())\ntele = list(map(int,input().split()))\nk = 1\nflag = [0]*N\ngoal = tele[0]\nmiti = [1]\nwhile (flag[goal-1])!=1:\n k += 1\n miti.append(goal)\n flag[goal-1] = 1\n goal = tele[goal-1]\n if k == K:\n print(goal)\n sys.exit()\n\na = miti.index(goal)\nloop = k-a\nans = miti[(K-a)%loop+a]\n\nprint(ans)']
|
['Wrong Answer', 'Accepted']
|
['s441597903', 's508742786']
|
[32244.0, 32380.0]
|
[2206.0, 173.0]
|
[358, 351]
|
p02684
|
u013513417
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\nfor i in range(N):\n A[i]-=1\n\n\nS = [0]*N\nL = []\nS[0]=1\nL.append(1)\ncount=1\npos=A[0]\n\n\nif A[0]==0:\n print(1)\n exit()\n\nfor i in range(N+1):\n \n if S[pos]==0:\n count+=1\n S[pos]=count\n L.append(pos+1)\n pos=A[pos]\n \n else:\n roopcount=count-S[pos]+1\n break\n\n\nif count-1>=K:\n ans=L[K+1]\n\nelse:\n K=K-(count-roopcount)\n K=K%roopcount\n ans=L[K+count-roopcount]\n \nprint(ans,count,roopcount)', 'from collections import deque\n\nN,K=map(int,input().split())\nA=list(map(int,input().split()))\nif A[0]==1:\n print(1)\n exit()\nif K==1:\n print(A[0])\n exit()\nfor i in range(N):\n A[i]-=1\n\n\n\nS = [0]*N\nL = deque()\nS[0]=1\nL.append(1)\ncount=1\npos=A[0]\n\nfor i in range(N+1):\n \n if S[pos]==0:\n count+=1\n S[pos]=count\n L.append(pos+1)\n pos=A[pos]\n \n else:\n roopcount=count-S[pos]+1\n L.append(pos+1)\n break\n\n\nif count>K:\n ans=L[K]\n\nelse:\n K=K-(count-roopcount)\n K=K%roopcount\n for i in range(count-roopcount):\n ret=L.popleft()\n ans=L[K]\n \nprint(ans,count,L)', 'from collections import deque\n\nN,K=map(int,input().split())\nA=list(map(int,input().split()))\nif A[0]==1:\n print(1)\n exit()\nif K==1:\n print(A[0])\n exit()\nfor i in range(N):\n A[i]-=1\n\n\n\nS = [0]*N\nL = deque()\nS[0]=1\nL.append(1)\ncount=1\npos=A[0]\n\nfor i in range(N+1):\n \n if S[pos]==0:\n count+=1\n S[pos]=count\n L.append(pos+1)\n pos=A[pos]\n \n else:\n roopcount=count-S[pos]+1\n L.append(pos+1)\n break\n\n\nif count>K:\n ans=L[K]\n\nelse:\n K=K-(count-roopcount)\n K=K%roopcount\n for i in range(count-roopcount):\n ret=L.popleft()\n ans=L[K]\n \nprint(ans)']
|
['Wrong Answer', 'Wrong Answer', 'Accepted']
|
['s071731882', 's086336658', 's526702966']
|
[32480.0, 38668.0, 33868.0]
|
[218.0, 225.0, 201.0]
|
[587, 714, 706]
|
p02684
|
u014800961
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['\nn,k = map(int,input().split())\nalist = list(map(int,input().split()))\n\ntown_loop = [1]\nused = [-1] * n\n\nfor i in range(k):\n next_town = alist[town_loop[i]-1]\n\n if used[next_town-1] == -1:\n town_loop.append(next_town)\n used[next_town-1] = 1\n break\n else:\n break\n\nloop_start = town_loop.index(next_town)\nif len(town_loop) == k+1:\n print(town_loop[k])\nelse:\n o = len(town_loop) - loop_start\n print(town_loop[((k-loop_start) % o) + loop_start])\n', '\nn,k = map(int,input().split())\nalist = list(map(int,input().split()))\n\ntown_loop = [1]\n\nfor i in range(k):\n next_town = alist[town_loop[i]-1]\n\n try:\n loop_start = town_loop.index(next_town)\n break\n except ValueError:\n town_loop.append(next_town)\n \nif len(town_loop) == k-1:\n print(town_loop[k-1])\nelse:\n o = len(town_loop) - loop_start\n print(town_loop[((k+1) % o) + loop_start])\n', '\nn,k = map(int,input().split())\nalist = list(map(int,input().split()))\n\ntown_loop = [1]\nused = [-1] * n\n\nfor i in range(k):\n next_town = alist[town_loop[i]-1]\n\n if used[next_town-1] == -1:\n town_loop.append(next_town)\n used[next_town-1] = 1\n else:\n break\n\nloop_start = town_loop.index(next_town)\nif len(town_loop) == k+1:\n print(town_loop[k])\nelse:\n o = len(town_loop) - loop_start\n print(town_loop[((k-loop_start) % o) + loop_start])\n']
|
['Wrong Answer', 'Runtime Error', 'Accepted']
|
['s083837647', 's897705257', 's929752939']
|
[32276.0, 32380.0, 32308.0]
|
[71.0, 2206.0, 165.0]
|
[488, 427, 474]
|
p02684
|
u014958112
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import sys\nn, k = map(int, input().split())\na = list(map(int, input().split()))\nb = []\ncnt = 0\nnext_town = 0\n\nl = len(a) + 1\nfor j in range(l):\n if j==0:\n b.append(a[0])\n next_town = a[0]\n continue\n \n b.append(a[next_town - 1])\n next_town = a[next_town -1]\nprint(b)\nfor i in range(l):\n if b.count(i+1)==2:\n cnt = b.index(i+1)\n k -= cnt\n indexes = [p for p, x in enumerate(b) if x == i+1]\n roop_list = b[indexes[0]:indexes[1]]\n roop_num = indexes[1]-indexes[0]\n last = k %roop_num\n\n print(roop_list[last-1])\n sys.exit()\n\n', 'N, K =map(int, input().split())\nA = [int(a) - 1 for a in input().split()]\nidx = 0\nif K<=N:\n for i in range(K):\n idx = A[idx]\n print(idx + 1)\n exit() \n\nt = [-1] * N\nt[0] = 0\nfor i in range(1, N):\n idx = A[idx]\n last = i\n if t[idx] != -1:\n break\n t[idx] = i\n\nd = i - t[idx]\nK = K - i\namari = K%d\n\nfor i in range(amari):\n idx = A[idx]\nprint(idx + 1)\n \n\n']
|
['Wrong Answer', 'Accepted']
|
['s011296582', 's683409328']
|
[32384.0, 32268.0]
|
[2206.0, 134.0]
|
[612, 425]
|
p02684
|
u015593272
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["def main():\n\n import sys\n input = sys.stdin.readline\n\n N_ko, K_kai = map(int, input().split())\n \n teleport = list(map(int, input().split()))\n\n index = 0\n ctr = 0\n before_ctr = 0\n\n Visited = []\n Visited.append(ctr)\n\n for i in range(N_ko + 1):\n\n ctr += 1\n index = teleport[index] - 1\n Visited.append(index)\n \n if (index == 0):\n FLAG = 1\n break\n\n if (len(Visited) != len(set(Visited))):\n FLAG = 0\n break\n\n\n if (FLAG):\n mod = K_kai % ctr\n city = 0\n\n for i in range(mod):\n city = teleport[city] - 1\n\n ans = city + 1\n \n else:\n ans = 0\n\n\n # else:\n # cnt = 0\n # before_ctr = 0\n\n \n # cnt += 1\n # current_index = teleport[index] - 1\n \n # if (current_index == index):\n # before_ctr = cnt\n # break\n \n \n # city = 0\n \n \n # city = teleport[city] - 1\n\n # ans = city + 1\n\n # else:\n # ans = (K_kai - before_ctr) % (ctr - before_ctr)\n # ans += 1\n \n\n # print(ans)\n\n\nif __name__ == '__main__':\n main()", "def main():\n\n N_machi, K_teleport = map(int, input().split())\n to_teleport = list(map(int, input().split()))\n\n visited_city = [1]\n order = [-1 for i in range(N_machi + 1)]\n order[1] = 0\n next_city = 1\n \n for i in range(N_machi):\n next_city = to_teleport[next_city - 1]\n tmp = order[next_city]\n \n if (tmp == -1):\n visited_city.append(next_city)\n order[next_city] = i + 1\n else:\n break\n \n first = order[next_city]\n len_loop = len(visited_city) - first\n \n if (K_teleport < first):\n ans = visited_city[K_teleport]\n else:\n mod = (K_teleport - first) % len_loop\n ans = visited_city[first + mod]\n \n print(ans)\n \n\nif __name__ == '__main__':\n main()"]
|
['Wrong Answer', 'Accepted']
|
['s287842724', 's138090924']
|
[31268.0, 33384.0]
|
[2206.0, 158.0]
|
[1341, 787]
|
p02684
|
u017415492
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\na=list(map(int,input().split()))\ns=1\nsa=set()\nd=dict()\ncount=0\nniko=0\nanss=0\nbx=False\nwhile True:\n count+=1\n if count+1==k:\n anss=a[s]\n bx=True\n print(a[s])\n count-1\n break\n if not (a[s-1] in sa):\n sa.add(a[s-1])\n d[a[s-1]]=count\n s=a[s-1]\n else:\n niko=a[s-1]\n number=count-d[a[s-1]]\n break\nif bx==False:\n lf=False\n ans_list=[]\n kaisu=0\n for i,j in d.items():\n if i==niko:\n lf=True\n kaisu=j\n if lf==True:\n ans_list.append(i)\n print(ans_list[(k-kaisu)%number])\n \n \n \n ', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\ns=1\nsa=set()\nd=dict()\ncount=0\nniko=0\nanss=0\nbx=False\nwhile True:\n count+=1\n if count==k:\n anss=a[s-1]\n bx=True\n print(a[s-1])\n count-1\n break\n if not (a[s-1] in sa):\n sa.add(a[s-1])\n d[a[s-1]]=count\n s=a[s-1]\n else:\n niko=a[s-1]\n number=count-d[a[s-1]]\n break\nif bx==False:\n lf=False\n ans_list=[]\n kaisu=0\n for i,j in d.items():\n if i==niko:\n lf=True\n kaisu=j\n if lf==True:\n ans_list.append(i)\n print(ans_list[(k-kaisu)%number])\n \n \n \n ']
|
['Wrong Answer', 'Accepted']
|
['s332638413', 's910374017']
|
[40724.0, 40796.0]
|
[239.0, 211.0]
|
[569, 571]
|
p02684
|
u018168283
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\niran=[]\nl=list(map(int,input().split()))\n#n,k=6,727202214173249351\n#l=[6,5,2,5,3,2]\nfor i in range(N):\n if l.count(i+1)==0:\n iran.append(i+1)\nkiseki=[]\n\nu=1\nkiseki.append(1)\nfor i in l:\n u=l[u-1]\n if kiseki.count(u)==0:\n kiseki.append(u)\n else:\n kiseki.append(u)\n break\nkuri=kiseki[kiseki.index(u):len(kiseki)-1]\nif k<=len(kiseki)-(len(kuri)+1):\n print(kiseki[k])\nelse:\n K=k-(len(kiseki)-(len(kuri)+1))\n amari=K%len(kuri)\n print(kuri[amari])', 'n,k=map(int,input().split())\nl=list(map(int,input().split()))\nkiseki=[-1]*n\ni=0\nv=1\nwhile kiseki[v-1]==-1:\n kiseki[v-1]=i\n v=l[v-1]\n i+=1\nsaisyo=kiseki[v-1]\nkuri=i-saisyo\n\nif saisyo>k:\n print(kiseki.index(k)+1)\nelse:\n amari=(k-saisyo)%kuri\n print(kiseki.index(amari+saisyo)+1)']
|
['Runtime Error', 'Accepted']
|
['s922789594', 's122456180']
|
[32316.0, 32384.0]
|
[69.0, 150.0]
|
[513, 282]
|
p02684
|
u020962106
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["n,k=map(int,input().split())\na = list(map(int,input().split()))\nrep = []\nrep.append(1)\ni = 0\ncnt = 0\nif n>k:\n end =k\nelse:\n end =n\nnof = 0\nwhile True:\n cnt+=1\n if cnt>end:\n nof=1\n break\n go = a[i]-1\n if a[i] not in rep:\n rep.append(a[i])\n i = go\n else:\n rep.append(a[i])\n break\nif nof==1:\n print(rep[k])\nelse:\n print('oo')\n # lr = len(rep)\n \n # if rep[i]==rep[lr-1]:\n # start=i\n # rep2 = rep[i:lr-1]\n # break\n # mod = len(rep2)\n \n # resM = k%mod\n \n # if resM == modL[i]:\n # print(rep2[i])", 'n,k=map(int,input().split())\na = list(map(int,input().split()))\nvisit = []\nvisit = [0]*n\npos=0\nmove=[]\nroop=[]\nwhile visit[pos]!=2:\n if visit[pos]==0:\n move.append(pos)\n else:\n roop.append(pos)\n visit[pos]+=1\n pos = a[pos]-1\nif len(move)>k:\n print(move[k]+1)\nelse:\n mod = (k-(len(move)-len(roop)))%len(roop)\n print(roop[mod]+1)']
|
['Wrong Answer', 'Accepted']
|
['s663651072', 's587810272']
|
[32376.0, 32744.0]
|
[2206.0, 208.0]
|
[724, 362]
|
p02684
|
u023185908
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["n,k = map(int, input().split())\na = list(map(int, input().split()))\nimport numpy as np\nlink = set()\nnext = a[0]\nlink.add(1)\nwhile next not in link:\n link.add(next)\n next = a[next-1]\nprint(next)\n# print(link)\n\nlink2 = set()\nnext2 = a[0]\nlink2.add(1)\nwhile next not in link2:\n link2.add(next2)\n next2 = a[next2-1]\n\nlink2.remove(next)\nans = 0\n# if len(link2) == 1 :\n# print('a')\n# rep = len(link)+1-len(link2)\n# else:\nprint('b')\nrep = len(link)- len(link2)\n\nif(k > len(link2)):\n # if len(link2) == 1:\n # print('c')\n # p = (k-len(link2)+2)%rep\n # print(p)\n\n print('d')\n p = (k-len(link2)+1)%rep\n # print(p)\n #\n # print(next)\n for i in range(p+rep-1):\n next = a[next-1]\n print('e')\nelse:\n print('f')\n next = 0\n for i in range(k):\n next = a[next-1]\n\nans = next\nprint(link)\nprint(link2)\nprint(ans)\n", 'n,k = map(int, input().split())\na = list(map(int, input().split()))\nimport numpy as np\nlink = set()\nnext = a[0]\nlink.add(1)\nwhile next not in link:\n link.add(next)\n next = a[next-1]\n\nprint(next)\nlink2 = set()\nnext2 = a[0]\nlink2.add(1)\nwhile next not in link2:\n link2.add(next2)\n next2 = a[next2-1]\n\nlink2.remove(next)\nans = 0\n\nrep = len(link) - len(link2)\nprint(rep)\nif (len(link2) == 0):\n p = k%rep\n for i in range(p+rep):\n next = a[next-1]\nelif(k > len(link2)):\n p = (k-len(link2))%rep\n for i in range(p+rep):\n next = a[next-1]\nelse:\n next = 0\n for i in range(k-1):\n next = a[next-1]\n\nans = next\nprint(ans)\n', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\nimport numpy as np\nlink = set()\nnext = a[0]\nlink.add(1)\nwhile next not in link:\n link.add(next)\n next = a[next-1]\n\nlink2 = set()\nnext2 = a[0]\nlink2.add(1)\nwhile next not in link2:\n link2.add(next2)\n next2 = a[next2-1]\n\nlink2.remove(next)\nans = 0\n\nrep = len(link)- len(link2)\n\nif(k > len(link2)):\n p = (k-len(link2))%rep\n for i in range(p+rep-1):\n next = a[next-1]\nelse:\n next = 0\n for i in range(k-1):\n next = a[next-1]\n\nans = next\nprint(ans)\n', "n,k = map(int, input().split())\na = list(map(int, input().split()))\nimport numpy as np\nlink = set()\nnext = a[0]\nlink.add(1)\nwhile next not in link:\n link.add(next)\n next = a[next-1]\n\n# print(next)\nlink2 = set()\nnext2 = a[0]\nlink2.add(1)\nwhile next not in link2:\n link2.add(next2)\n next2 = a[next2-1]\n\nlink2.remove(next)\nans = 0\n\nrep = len(link) - len(link2)\n# print(rep)\nif (len(link2) == 0):\n p = k%rep\n # print('e')\n for i in range(p+rep):\n next = a[next-1]\nelif(k > len(link2)):\n # print('f')\n p = (k-len(link2))%rep\n # print(p)\n # print(next)\n for i in range(p+rep):\n next = a[next-1]\nelse:\n # print('d')\n next = a[0]\n for i in range(k-1):\n next = a[next-1]\n# print(next)\nans = next\n# print(link,link2)\nprint(ans)\n"]
|
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
|
['s682373861', 's694019199', 's953051426', 's095821194']
|
[57500.0, 57824.0, 57824.0, 57772.0]
|
[375.0, 334.0, 342.0, 346.0]
|
[879, 660, 549, 784]
|
p02684
|
u024340351
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n \nB = []\nVector = [0]*N\nj = 0\n \nfor i in range (0,K+1):\n\tif Vector(A[j]) == 1:\n\t\tValue = B.index(A[j])\n\t\tC = B[B.index(A[j])::]\n\t\tbreak\n\telse:\n\t\tB.append(A[j])\n\t\tVector(A[j]) = 1\n\t\tj = A[j]-1\n\nif A[0] ==1:\n\tprint(1)\nelif len(B) == K:\n\tprint(B[-1])\nelse:\n\tprint(C[(K-Value-1)%len(C)])', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n \nB = []\nVector = [0]*N\nj = 0\n \nfor i in range (0,K+1):\n\tif Vector[A[j]] == 1:\n\t\tValue = B.index(A[j])\n\t\tC = B[B.index(A[j])::]\n\t\tbreak\n\telse:\n\t\tB.append(A[j])\n\t\tVector[A[j]] = 1\n\t\tj = A[j]-1\n\nif A[0] ==1:\n\tprint(1)\nelif len(B) == K:\n\tprint(B[-1])\nelse:\n\tprint(C[(K-Value-1)%len(C)])', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n \nB = []\nVector = [0]*N\nj = 0\n \nfor i in range (0,K):\n\tif Vector[A[j]-1] == 1:\n\t\tValue = B.index(A[j])\n\t\tC = B[B.index(A[j])::]\n\t\tbreak\n\telse:\n\t\tB.append(A[j])\n\t\tVector[A[j]-1] = 1\n\t\tj = A[j]-1\n\nif A[0] ==1:\n\tprint(1)\nelif len(B) == K:\n\tprint(B[-1])\nelse:\n\tprint(C[(K-Value-1)%len(C)])']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s166620571', 's420151493', 's204542754']
|
[9156.0, 32224.0, 32244.0]
|
[24.0, 133.0, 151.0]
|
[352, 352, 354]
|
p02684
|
u024768467
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int,input().split())\na_list = [0] + list(map(int,input().split()))\n\ntown_num_tmp = 1 \nseen = [-1]*(n+1) \ntown_hist_list = []\n\nwhile seen[town_num_tmp] == -1:\n seen[town_num_tmp] = 1\n town_hist_list.append(town_num_tmp)\n \n town_num_tmp = a_list[town_num_tmp]\n\nroop_end = len(town_hist_list)\nroop_start = town_hist_list.index(town_num_tmp)\nroop_range = roop_end - roop_start\n\nif k < roop_end:\n print(town_hist_list[k])\nelse:\n print(town_hist_list[(k-roop_start)%roop_range+roop_start-1])', 'n,k = map(int,input().split())\na_list = [0] + list(map(int,input().split()))\n\ntown_num_tmp = 1 \nseen = [-1]*(n+1) \ntown_hist_list = []\n\nwhile seen[town_num_tmp] == -1:\n seen[town_num_tmp] = 1\n town_hist_list.append(town_num_tmp)\n \n town_num_tmp = a_list[town_num_tmp]\n\nroop_end_index = len(town_hist_list) - 1\nroop_start_index = town_hist_list.index(town_num_tmp)\nroop_range = roop_end_index - roop_start_index + 1\n\nif k < roop_end_index:\n print(town_hist_list[k])\nelse:\n print(town_hist_list[(k-roop_start_index)%roop_range+roop_start_index])']
|
['Wrong Answer', 'Accepted']
|
['s456833077', 's412930978']
|
[32268.0, 32292.0]
|
[164.0, 172.0]
|
[613, 661]
|
p02684
|
u025463382
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int,input().split())\na = [int(i)-1 for i in input().split()]\ncounter = 1\ncur = 0\nmem = [0]\nwhile True:\n if counter == k:\n ans = cur +1\n break\n cur = a[cur]\n mem.append(cur)\n counter += 1\n if cur == 0:\n k = k%counter\n ans = mem[k]\n break\nprint(ans)', 'n,k = map(int,input().split())\na = [int(i)-1 for i in input().split()]\ncounter = 0\ncur = 0\nmem = [0]\nfiv = [False]*n\nfiv[0] = True\nwhile True:\n if counter == k:\n ans = cur +1\n break\n cur = a[cur]\n \n #print(cur)\n \n mem.append(cur)\n counter += 1\n if fiv[cur]:\n if fiv[0] == True:\n fiv[0] = 0\n roop = counter -fiv[cur]\n k -= fiv[cur]\n k %= roop\n #print(k)\n ans = mem[k+fiv[cur]] +1\n break\n fiv[cur] = counter\n #print(counter,fiv,mem)\nprint(ans)']
|
['Wrong Answer', 'Accepted']
|
['s318611920', 's820383727']
|
[101816.0, 32328.0]
|
[2208.0, 153.0]
|
[292, 514]
|
p02684
|
u031157253
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['from collections import deque\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n A.insert(0, 0)\n J = [-1] * (N + 1)\n T = []\n que = deque([1])\n count = 0\n l = 0\n while que:\n i = que.popleft()\n if J[i] != -1:\n l = J[i]\n break\n J[i] = count\n count += 1\n T.append(i)\n que.append(A[i])\n if K < l:\n return T[K]\n else:\n return T[(K-(l+1))%(len(T)-l)]\nprint(main())', 'from collections import deque\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n A.insert(0, 0)\n J = [-1] * (N + 1)\n T = []\n que = deque([1])\n count = 0\n l = 0\n while que:\n i = que.popleft()\n if J[i] != -1:\n l = J[i]\n break\n J[i] = count\n count += 1\n T.append(i)\n que.append(A[i])\n if K < l:\n return T[K]\n else:\n return T[(K-l)%(len(T)-l) + l]\nprint(main())\n']
|
['Wrong Answer', 'Accepted']
|
['s633484486', 's644719420']
|
[33920.0, 33808.0]
|
[169.0, 164.0]
|
[501, 502]
|
p02684
|
u033272694
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K = map(int,input().split())\nlist1 = list(map(int,input().split()))\nvisited_town = [[] for i in range(N+1)] \nvisited_time = [None for i in range(2*N)] \n\nvisited_town[1].append(0) \nvisited_time[0] = 1\n\ncycle_start = -1\ncycle_end = -1\ncycle_detect = False\n\nfor i in range(1,min([K,2*N])):\n next_town = list1[visited_time[i-1]-1]\n visited_town[next_town].append(i)\n visited_time[i] = next_town\n if len(visited_town[next_town]) == 2:\n cycle_start = visited_town[next_town][0]\n cycle_end = visited_town[next_town][1]\n cycle_detect = True\n break\n\nprint(visited_time)\n\nif (!cycle_detect)\n ans = visited_time[K]\n print(ans)\nelse : \n syuuki = cycle_end-cycle_start\n cycle = visited_time[cycle_start:cycle_end]\n ans = cycle[(K-cycle_start) % syuuki]\n print(ans)\n', 'N,K = map(int,input().split())\nlist1 = list(map(int,input().split()))\nvisited_town = [[] for i in range(N+1)] \nvisited_time = [None for i in range(2*N)] \n\nvisited_town[1].append(0) \nvisited_time[0] = 1\n\ncycle_start = -1\ncycle_end = -1\n\nfor i in range(1,2*N):\n next_town = list1[visited_time[i-1]-1]\n visited_town[next_town].append(i)\n visited_time[i] = next_town\n if len(visited_town[next_town]) == 2:\n cycle_start = visited_town[next_town][0]\n cycle_end = visited_town[next_town][1]\n break\n\nif K < cycle_start:\n ans = visited_time[K]\n print(ans)\nelse : \n syuuki = cycle_end-cycle_start\n cycle = visited_time[cycle_start:cycle_end]\n ans = cycle[(K-cycle_start) % syuuki]\n print(ans)']
|
['Runtime Error', 'Accepted']
|
['s774001442', 's708364316']
|
[9092.0, 48372.0]
|
[25.0, 310.0]
|
[890, 815]
|
p02684
|
u036065030
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import numpy as np\n\ndef check_num_of_remaining_teleport(num_of_teleport, i):\n if num_of_teleport == 0:\n print(i)\n exit()\n\nnum_of_town, num_of_teleport = map(int, input().split())\ntown = np.array(list(map(int, input().split())))\n\n\ni = 1\n\nfragranttown_index = 1\nfragrants = [0] * num_of_town\nfragrants[0] = 1\nfor _ in range(num_of_town):\n print(num_of_teleport)\n i = town[i - 1]\n num_of_teleport = num_of_teleport - 1\n\n \n check_num_of_remaining_teleport(num_of_teleport, i)\n\n \n if fragrants[i - 1] != 1:\n fragrants[i - 1] = 1\n else:\n fragranttown_index = i\n break\n\n\n\nrevisit = 0\nj = fragranttown_index\nfor _ in range(num_of_town):\n print(num_of_teleport)\n j = town[j - 1]\n revisit = revisit + 1\n num_of_teleport = num_of_teleport - 1\n\n \n check_num_of_remaining_teleport(num_of_teleport, j)\n\n \n if fragranttown_index == j:\n break\n\n\nnum_of_last_teleport = num_of_teleport % revisit\nk = fragranttown_index\nlasttown_index = fragranttown_index\n\nfor _ in range(num_of_last_teleport):\n lasttown_index = k\n k = town[k - 1]\n \nprint(lasttown_index)\n', 'import numpy as np\n\ndef check_num_of_remaining_teleport(num_of_teleport, i):\n if num_of_teleport == 0:\n print(i)\n exit()\n\nnum_of_town, num_of_teleport = map(int, input().split())\ntown = np.array(list(map(int, input().split())))\n\n\ni = 1\n\nfragranttown_index = 1\nfragrants = [0] * num_of_town\nfragrants[0] = 1\nfor _ in range(num_of_town):\n i = town[i - 1]\n num_of_teleport = num_of_teleport - 1\n\n \n check_num_of_remaining_teleport(num_of_teleport, i)\n\n \n if fragrants[i - 1] != 1:\n fragrants[i - 1] = 1\n else:\n fragranttown_index = i\n break\n\n\n\nrevisit = 0\nj = fragranttown_index\nfor _ in range(num_of_town):\n j = town[j - 1]\n revisit = revisit + 1\n num_of_teleport = num_of_teleport - 1\n\n \n check_num_of_remaining_teleport(num_of_teleport, j)\n\n \n if fragranttown_index == j:\n break\n\n\nnum_of_last_teleport = num_of_teleport % revisit\nk = fragranttown_index\n\nfor _ in range(num_of_last_teleport):\n k = town[k - 1]\n \nprint(k)\n']
|
['Wrong Answer', 'Accepted']
|
['s983003826', 's077990775']
|
[50948.0, 50936.0]
|
[510.0, 412.0]
|
[1534, 1408]
|
p02684
|
u036104576
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import sys\nimport itertools\nimport numpy as np\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n \nN, K = map(int, readline().split())\nA = list(map(lambda x: x - 1, map(int, readline().split())))\nvisited = [False for i in range(N)]\n\ncur = 0\ncycle = []\nstart = 0\nwhile True:\n if visited[cur]:\n start = cur + 1\n break\n\n visited[cur] = True\n cycle.append(cur + 1)\n cur = A[cur]\n\nprint(cycle)\ncycle_start_idx = 0\nfor i in range(len(cycle)):\n if cycle[i] == start:\n cycle_start_idx = i\n break\n\nif K <= cycle_start_idx:\n print(cycle[K])\n exit()\n\n\ncycle_len = len(cycle) - cycle_start_idx\nidx = (K - cycle_start_idx) % cycle_len\nprint(cycle[idx + cycle_start_idx])', 'import sys\nimport itertools\nimport numpy as np\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n \nN, K = map(int, readline().split())\nA = list(map(lambda x: x - 1, map(int, readline().split())))\nvisited = [False for i in range(N)]\n\ncur = 0\ncycle = []\nstart = 0\nwhile True:\n if visited[cur]:\n start = cur + 1\n break\n\n visited[cur] = True\n cycle.append(cur + 1)\n cur = A[cur]\n\n# print(cycle)\ncycle_start_idx = 0\nfor i in range(len(cycle)):\n if cycle[i] == start:\n cycle_start_idx = i\n break\n\nif K <= cycle_start_idx:\n print(cycle[K])\n exit()\n\n\ncycle_len = len(cycle) - cycle_start_idx\nidx = (K - cycle_start_idx) % cycle_len\nprint(cycle[idx + cycle_start_idx])']
|
['Wrong Answer', 'Accepted']
|
['s925754387', 's574544852']
|
[47276.0, 46316.0]
|
[310.0, 251.0]
|
[762, 764]
|
p02684
|
u038724782
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int,input().split())\na_l = list(map(int,input().split()))\n\ntown = 1\ncount = 0\ntown_visited = set()\nwhile count < k:\n town_visited.add(town)\n town = a_l[town-1]\n count += 1\n if town in town_visited:\n break\n\nk -= count\nif k = 0:\n print(town)\n exit()\ncount = 0\ntown_visited = set()\nwhile count < k:\n town_visited.add(town)\n town = a_l[town-1]\n count += 1\n if town in town_visited:\n break\n\nremain = k%count\ncount = 0\nwhile count < remain:\n town = a_l[town-1]\n count += 1\n \nprint(town)', 'n, k = map(int,input().split())\na_l = list(map(int,input().split()))\n\ntown = 1\ncount = 0\ntown_visited = set()\nwhile count < k:\n town_visited.add(town)\n town = a_l[town-1]\n count += 1\n if town in town_visited:\n break\n\nk -= count\nif k == 0:\n print(town)\n exit()\ncount = 0\ntown_visited = set()\nwhile count < k:\n town_visited.add(town)\n town = a_l[town-1]\n count += 1\n if town in town_visited:\n break\n\nremain = k%count\ncount = 0\nwhile count < remain:\n town = a_l[town-1]\n count += 1\n \nprint(town)']
|
['Runtime Error', 'Accepted']
|
['s693219077', 's521898248']
|
[9040.0, 32404.0]
|
[25.0, 165.0]
|
[543, 544]
|
p02684
|
u042113240
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int,input().split())\nA = list(map(int,input().split()))\nX = [-1 for j in range(N)]\nX[0] = 0\nY = [0]\ni = 0\nNum = 0\nMM = 0\nfor k in range(1,N):\n i = A[i]-1\n if k == K:\n MM = 1\n P = i\n elif X[i] != -1:\n Num = X[i]\n break\n else:\n X[i] = k\n Y.append(i)\nY = Y[Num:]\nB = (K-Num)%len(Y)\nif MM = 1:\n print(P+1)\nelse:\n print(Y[B]+1)', 'N, K = map(int,input().split())\nA = list(map(int,input().split()))\nX = [-1 for j in range(N)]\nX[0] = 0\nY = [0]\ni = 0\nNum = 0\nMM = 0\nfor k in range(1,N):\n i = A[i]-1\n if k = K:\n MM = 1\n P = i\n elif X[i] != -1:\n Num = X[i]\n break\n else:\n X[i] = k\n Y.append(i)\nY = Y[Num:]\nB = (K-Num)%len(Y)\nif MM = 1:\n print(P+1)\nelse:\n print(Y[B]+1)', 'N, K = map(int,input().split())\nA = list(map(int,input().split()))\nX = [-1 for j in range(N)]\nX[0] = 0\nY = [0]\ni = 0\nNum = 0\nMM = 0\nfor k in range(1,N):\n i = A[i]-1\n if k == K:\n MM = 1\n P = i\n break\n elif X[i] != -1:\n Num = X[i]\n break\n else:\n X[i] = k\n Y.append(i)\nY = Y[Num:]\nB = (K-Num)%len(Y)\nif MM == 1:\n print(P+1)\nelse:\n print(Y[B]+1)']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s659344235', 's980078166', 's576706382']
|
[9104.0, 9048.0, 32248.0]
|
[23.0, 23.0, 172.0]
|
[357, 356, 368]
|
p02684
|
u048176319
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nla = list(map(int, input().split()))\n\nlc = [1]\nlcnt = [1]\nlcnt.extend([0]*(N-1))\nprint(lcnt)\ni = 1\nwhile lcnt[lc[i-1]-1] == 1:\n if i == N:\n break\n else:\n lc.append(la[lc[i-1]-1])\n lcnt[la[lc[i-1]-1]-1] += 1\n i += 1\nprint("lcnt =", lcnt)\nprint("lc =", lc)\n\nlpst = lc.index(lc[-1])\nlpnum = len(lc) - lpst - 1\nif K <= lpst:\n loclst = K\nelif lpnum == 0:\n loclst = lpst\nelse:\n loclst = (K - lpst) % lpnum + lpst\nprint(lpst, lpnum)\nprint(lc[loclst])', 'N, K = map(int, input().split())\nla = list(map(int, input().split()))\n\nlc = [1]\nlcnt = [1]\nlcnt.extend([0]*(N-1))\n\ni = 1\nwhile lcnt[lc[i-1]-1] == 1:\n if i == N:\n break\n else:\n lc.append(la[lc[i-1]-1])\n lcnt[la[lc[i-1]-1]-1] += 1\n i += 1\n\nlpst = lc.index(lc[-1])\nlpnum = len(lc) - lpst - 1\nif K <= lpst:\n loclst = K\nelif lpnum == 0:\n loclst = lpst\nelse:\n loclst = (K - lpst) % lpnum + lpst\n\nprint(lc[loclst])']
|
['Wrong Answer', 'Accepted']
|
['s127857828', 's491635007']
|
[32384.0, 32112.0]
|
[286.0, 212.0]
|
[519, 450]
|
p02684
|
u048800107
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["import sys\ninput = sys.stdin.readline\ndef main():\n n,k = map(int,input().split())\n l = list(map(int,input().split()))\n position = 1\n\n town = ''\n stayed = [1]+[0]*n\n stayed_c = [0]*n\n for i in range(n):\n position = l[position-1]\n if not position in stayed:\n stayed[position-1] = position\n stayed_c[position-1] = i+1\n else:\n c = i+1 - stayed_c[position-1]\n g = stayed_c[position-1]\n town = position\n break\n m = (k -g) % c \n position = town\n for i in range(m):\n position = l[position-1]\n print(position) \n ", "n,k = map(int,input().split())\nl = list(map(int,input().split()))\nposition = 1\ntown = ''\nstayed = [1]\nstayed_c = [0]*n\nfor i in range(n):\n position = l[position-1]\n if not position in stayed:\n stayed.append(position)\n stayed_c[i] = i+1\n else:\n c = i+1 - stayed_c[position-1]\n g = stayed_c[position-1]\n town = position\n break\nm = abs((k % c) - g)\nposition = town\nfor i in range(m):\n position = l[position-1]\nprint(position) \n# print(m,g,k)\n", "\n\nn,k = map(int,input().split())\nl = list(map(int,input().split()))\nposition = 1\ntown = ''\nstayed = [1]\nstayed_c = [0]*n\nfor i in range(n):\n position = l[position-1]\n if not position in stayed:\n stayed.append(position)\n stayed_c[i] = i+1\n else:\n c = i+1 - stayed_c[position-1]\n town = position\n break\nm = k % c\nposition = 1\nfor i in range(m):\n position = l[position-1]\n\nprint(position) ", "n,k = map(int,input().split())\nl = list(map(int,input().split()))\nposition = 1\ntown = ''\nstayed = [1]\nstayed_c = [0]*n\nfor i in range(n):\n position = l[position-1]\n if not position in stayed:\n stayed.append(position)\n stayed_c[i] = i+1\n else:\n c = i+1 - stayed_c[position-1]\n k = stayed_c[position-1]\n town = position\n break\nm = (k % c) - k\nposition = town\nfor i in range(m):\n position = l[position-1]\nprint(position) \n", 'import sys\ninput = sys.stdin.readline\ndef main():\n n,k = map(int,input().split())\n l = list(map(int,input().split()))\n roop = [1]\n stayed = [0]*n\n for i in range(n):\n next_city = l[roop[-1]-1]\n if stayed[next_city-1]:\n endindex = i\n for j,r in enumerate(roop):\n if r == next_city:\n startindex = j\n break\n else:\n roop.append(next_city)\n stayed[next_city-1] = 1\n\n if k < startindex:\n print(roop[k])\n else:\n dis = endindex - startindex + 1\n a = (k - startindex) % dis\n print(roop[a + startindex])\nmain()']
|
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
|
['s235325974', 's666000772', 's686363640', 's804323515', 's484470621']
|
[9084.0, 32276.0, 32300.0, 32304.0, 31372.0]
|
[23.0, 2206.0, 2206.0, 2206.0, 139.0]
|
[633, 493, 433, 473, 659]
|
p02684
|
u048915776
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\na=list(input().split())\np[0]=int(a[0])-1\nf=0\nfor i in range(k-1):\n p[i+1]=int(a[p])-1\n for j in range(i+1):\n if p[i+1] == p[j]:\n r=j\n q=j-i-1\n f=1\n break\n if f==1:\n break\nk-=r\nk%=q\ns=p[r+k-1]\nif f==0: \n print(p[k-1]+1)\nelse:\n print(s)', 'n,k=map(int,input().split())\na=list(input().split())\np = [0]*200000\nq = [0]*200000\np[0]=1\np[1]=int(a[0])\nq[0]=1\nq[p[1]-1]=2\nf=0\nfor i in range(k-1):\n p[i+2]=int(a[p[i+1]-1])\n if q[p[i+2]]>0:\n r=q[p[i+2]]\n q=i+2-r\n f=1\n break\n if f==1:\n break\n q[p[i+2]]=i+3\nl=k-r\nl%=q\ns=p[r+l]\nif f==0: \n print(p[k])\nelse:\n print(s)', 'n,k=map(int,input().split())\na=list(input().split())\np = [0]*200000\nq = [0]*200000\np[0]=1\np[1]=int(a[0])\nq[0]=1\nq[p[1]-1]=2\nf=0\nfor i in range(k-1):\n p[i+2]=int(a[p[i+1]-1])\n if q[p[i+2]-1]>0:\n r=q[p[i+2]-1]-1\n q=i+2-r\n f=1\n l=k-r\n l%=q\n s=p[r+l]\n break\n if f==1:\n break\n q[p[i+2]-1]=i+3\nif f==0: \n print(p[k])\nelse:\n print(s)']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s432486471', 's657431008', 's390664606']
|
[25664.0, 34000.0, 36324.0]
|
[48.0, 144.0, 190.0]
|
[339, 371, 403]
|
p02684
|
u051358943
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import math\n\ndef solve():\n N, K = map(int,input().split())\n A = list(map(int, input().split()))\n\n state = 1\n chklist = [0] * (N + 1)\n chklist_flag = [False] * (N + 1)\n chkmod = 0\n\n chklist_flag[0] = True\n\n for i in range(1, K + 1):\n print(chklist)\n state = A[state - 1]\n if chklist_flag[state - 1]:\n chkmod = (K - chklist[state - 1]) % (i - chklist[state - 1]) \n break\n chklist[state - 1] = i \n chklist_flag[state - 1] = True\n\n for i in range(chklist[state - 1] + chkmod):\n state = A[state - 1]\n\n print(state)\n\nif __name__ == "__main__":\n solve()', 'import math\n\ndef solve():\n N, K = map(int,input().split())\n A = list(map(int, input().split()))\n\n state = 0\n chklist = [0] * N\n chklist_flag = [False] * N\n chkmod = 0\n\n chklist_flag[0] = True\n\n for i in range(1, K + 1):\n if chklist_flag[state - 1]:\n chkmod = (K - chklist[state - 1]) % (i - chklist[state - 1]) \n break\n chklist[state - 1] = i \n chklist_flag[state - 1] = True\n state = A[state]\n print(chklist_flag)\n\n for i in range(chklist[state - 1] + chkmod):\n chklist[state - 1] = i \n state = A[state- 1]\n\n print(state)\n\nif __name__ == "__main__":\n solve()', 'import math\n\ndef solve():\n N, K = map(int,input().split())\n A = list(map(int, input().split()))\n\n state = 1\n chklist = [0] * (N + 1)\n chklist_flag = [False] * (N + 1)\n \n chkmod = 0\n chkrem = K\n\n chklist_flag[0] = True\n\n for i in range(1, K + 1):\n state = A[state - 1]\n if chklist_flag[state - 1]:\n chkmod = (K - chklist[state - 1]) % (i - chklist[state - 1]) \n chkrem = chklist[state - 1]\n break\n chklist[state - 1] = i \n chklist_flag[state - 1] = True\n \n state = 1\n\n for i in range(chkrem + chkmod):\n state = A[state - 1]\n \n print(state)\n\nif __name__ == "__main__":\n solve()']
|
['Wrong Answer', 'Runtime Error', 'Accepted']
|
['s116079823', 's564165028', 's133045464']
|
[149044.0, 150284.0, 32252.0]
|
[2445.0, 972.0, 166.0]
|
[643, 663, 688]
|
p02684
|
u054556734
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int,input().split())\na = [0]+list(map(int,input().split()))\n\ndef bin(arr,val):\n left,right = 0,len(arr)-1\n while left<=right:\n mid = (left+right)//2\n if arr[mid]==val: return 1\n elif arr[mid]<val: left = mid + 1\n else: right = mid - 1\n return 0\n\nknow = []\nnow = 1\nwhile not bin(know, now):\n know.append(now)\n now = a[now]\n\nstart = a[know[-1]]\nfor i,num in enumerate(know):\n if num == start: loop = know[i:] ; break\n\nprint(know,start,loop)\n\nif k < len(know):\n ans = know[k]\nelse:\n k -= len(know)\n ans = loop[k%len(loop)]\n\nprint(ans)\n', 'n,k = map(int,input().split())\na = [0]+list(map(int,input().split()))\n\ndef bin(arr,val):\n left,right = 0,len(arr)-1\n while left<=right:\n mid = (left+right)//2\n if arr[mid]==val: return 1\n elif arr[mid]<val: left = mid + 1\n else: right = mid - 1\n return 0\n\nknow = []\nnow = 1\nwhile not bin(know, now):\n know.append(now)\n now = a[now]\n\nstart = a[know[-1]]\nfor i,num in enumerate(know):\n if num == start: loop = know[i:] ; break\n\n#print(know,start,loop)\n\nif k < len(know):\n ans = know[k]\nelse:\n k - = len(know)\n ans = know[k%len(loop)]\n\n\nprint(ans)\n', 'n,k = map(int,input().split())\na = [0]+list(map(int,input().split()))\n\ndef bin(arr,val):\n left,right = 0,len(arr)-1\n while left<=right:\n mid = (left+right)//2\n if arr[mid]==val: return 1\n elif arr[mid]<val: left = mid + 1\n else: right = mid - 1\n return 0\n\nknow = []\nnow = 1\nwhile not bin(know, now):\n know.append(now)\n now = a[now]\n\nstart = a[know[-1]]\nfor i,num in enumerate(know):\n if num == start: loop = know[i:] ; break\n\nprint(know,start,loop)\n\nif k < len(know):\n ans = know[k]\nelse:\n k - = len(know)\n ans = know[k%len(loop)]\n\n\nprint(ans)\n', 'n,k = map(int,input().split())\na = [0]+list(map(int,input().split()))\n\ndef bin(arr,val):\n left,right = 0,len(arr)-1\n while left<=right:\n mid = (left+right)//2\n if arr[mid]==val: return 1\n elif arr[mid]<val: left = mid + 1\n else: right = mid - 1\n return 0\n\nknow = []\nnow = 1\nwhile not bin(know, now):\n know.append(now)\n now = a[now]\n\nstart = a[know[-1]]\nfor i,num in enumerate(know):\n if num == start: loop = know[i:] ; break\n\n#print(know,start,loop)\n\nif k < len(know):\n ans = know[k]\nelse:\n k -= len(know)\n ans = loop[k%len(loop)]\n\nprint(ans)\n']
|
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s456413532', 's532389372', 's743106666', 's678081362']
|
[32284.0, 9080.0, 9012.0, 32388.0]
|
[818.0, 27.0, 23.0, 725.0]
|
[597, 600, 599, 598]
|
p02684
|
u060938295
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['# -*- coding: utf-8 -*-\n"""\nCreated on Sun May 10 20:50:56 2020\n"""\n\nimport sys\n#import numpy as np\n\nsys.setrecursionlimit(10 ** 9)\n#def input():\n# return sys.stdin.readline()[:-1]\nmod = 10**9+7\n\n#N = int(input())\nN,K = map(int,input().split())\nA = list(map(int,input().split()))\n\ncity = [False for i in range(N)]\ncity[1-1] =True\nnow = 1\n\ncounta1 = 0\nwhile True:\n counta1 += 1\n prev = now\n now = A[now-1]\n print(prev,now,counta1)\n if city[now-1]:\n break\n elif counta1 == K:\n print(now)\n sys.exit()\n else:\n city[now-1] = True\n\ncounta = 1\nrout = []\nrout.append(now)\nwhile now != prev:\n now = A[now-1]\n rout.append(now)\n counta +=1\n print(now,rout,counta)\n\nans = rout[(K-counta1) % counta]\nprint(ans)\n', '# -*- coding: utf-8 -*-\n"""\nCreated on Sun May 10 20:50:56 2020\n"""\n\nimport sys\n#import numpy as np\n\nsys.setrecursionlimit(10 ** 9)\n#def input():\n# return sys.stdin.readline()[:-1]\nmod = 10**9+7\n\n#N = int(input())\nN,K = map(int,input().split())\nA = list(map(int,input().split()))\n\ncity = [False for i in range(N)]\ncity[1-1] =True\nnow = 1\n\ncounta1 = 0\nwhile True:\n counta1 += 1\n prev = now\n now = A[now-1]\n# print(prev,now,counta1)\n if city[now-1]:\n break\n elif counta1 == K:\n print(now)\n sys.exit()\n else:\n city[now-1] = True\n\ncounta = 1\nrout = []\nrout.append(now)\nwhile now != prev:\n now = A[now-1]\n rout.append(now)\n counta +=1\n# print(now,rout,counta)\n\nans = rout[(K-counta1) % counta]\nprint(ans)\n']
|
['Runtime Error', 'Accepted']
|
['s084426201', 's372002968']
|
[146948.0, 32276.0]
|
[1896.0, 196.0]
|
[762, 764]
|
p02684
|
u067986021
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["N, K = [int(i) for i in input().split(' ')]\nA = [0]\nA.extend([int(a) for a in input().split(' ')])\ncheck_list = [0] * (N + 1)\n\ntown = 1\ncheck_point = 0\ninitial = -1\ninterval = -1\n\nprint(A)\n\nfor k in range(K):\n if check_list[town] > 0:\n check_point = town\n initial = check_list[town]\n interval = k - initial\n break\n check_list[town] = k\n print(check_list)\n town = A[town]\n\nremain = K - k\n\nrem = remain % interval\n\nprint(rem, remain, interval, initial)\n\ncheck_list_ = list(map(lambda x: x - initial, check_list))\n\nprint(check_list_)\n\nfor i, c in enumerate(check_list_):\n if c == rem:\n print(i)\n exit(0)", "N, K = [int(i) for i in input().split(' ')]\nA = [0]\nA.extend([int(a) for a in input().split(' ')])\ncheck_list = [0] * (N + 1)\n\ntown = 1\ncheck_point = 0\ninitial = -1\ninterval = -1\n\nfor k in range(K):\n if check_list[town] > 0:\n check_point = town\n initial = check_list[town]\n interval = k - initial\n break\n check_list[town] = k\n town = A[town]\n\nif interval == -1:\n print(town)\n exit(0)\n\nremain = K - k\n\nrem = remain % interval\n\ncheck_list_ = list(map(lambda x: x - initial, check_list))\n\nfor i, c in enumerate(check_list_):\n if c == rem:\n print(i)\n exit(0)"]
|
['Wrong Answer', 'Accepted']
|
['s383372812', 's942571865']
|
[148916.0, 32200.0]
|
[2818.0, 198.0]
|
[657, 614]
|
p02684
|
u078816252
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K = map(int,input().split())\nA = [0] + list(map(int,input().split()))\nans = 1\nn = 1\ncheck = 1\ncity = [-1 for i in range(N+1)]\ncity[1] = 0\nroop = 1\ni = 0\nwhile(check == 1):\n if i == K:\n check = 0\n else:\n n = A[n]\n i = i + 1 \n if city[n] == -1:\n city[n] = i\n else:\n roop = i - city[n] + 1\n check = 0\nroop_num = (K - i)%roop\nfor i in range(roop_num+1):\n n = A[n]\nprint(n)', 'N,K = map(int,input().split())\nA = [0] + list(map(int,input().split()))\nans = 1\nn = 1\ncheck = 1\ncity = [-1 for i in range(N+1)]\ncity[1] = 0\nroop = 1\ni = 0\nwhile(check == 1):\n if i == K:\n check = 0\n else:\n n = A[n]\n i = i + 1 \n if city[n] == -1:\n city[n] = i\n else:\n roop = i - city[n]\n check = 0\nroop_num = (K - i)%roop\nfor i in range(roop_num):\n n = A[n]\nprint(n)']
|
['Wrong Answer', 'Accepted']
|
['s247886577', 's365324304']
|
[32356.0, 32372.0]
|
[138.0, 147.0]
|
[403, 397]
|
p02684
|
u084865106
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["def main():\n n,k = map(int, input().split())\n a = list(map(int, input().split()))\n\n t = 1\n ans = [1]\n for i in range(n):\n if a[t-1] in ans :\n start = ans.index(a[t-1])\n break\n ans.append(a[t-1])\n t = a[t-1]\n\n index = k % (len(ans)-start)\n t = ans[index]\n return\n\nif __name__ == '__main__':\n main()\n", "def main():\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n\n path = [1]\n for _ in range(n-1):\n path.append(a[path[-1]-1])\n\n if k > n:\n start = path.index(path[-1])\n index = (k - start) % (len(path) - start - 1) + start\n t = path[index]\n else:\n t = path[k]\n return print(t)\n\nif __name__ == '__main__':\n main()\n"]
|
['Wrong Answer', 'Accepted']
|
['s750951623', 's025527796']
|
[32188.0, 32336.0]
|
[2206.0, 109.0]
|
[369, 393]
|
p02684
|
u090361088
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['Town = []\nC = 0\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\ndef dfs(a, i, town, c):\n if i-1 in town:\n L = len(town) - len(town[:town.index(i-1)])\n c += (K - c) - (K%L)\n town = []\n town.append(i-1)\n else:\n town.append(i-1)\n c += 1\n if c == K:\n return print(a[i-1])\n nx = a[i-1]\n dfs(a, nx, town, c)\n\ndfs(A, 1, Town, C)', 'Town = []\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\nvis = [0]*N\np = 1\nwhile vis[p-1]==0:\n Town.append(p)\n vis[p-1] = 1\n p = A[p-1]\n\nl = Town.index[p]\n\nif K < len(Town):\n print(Town[K])\nelse:\n print(Town[l + (K-l)%(len(Town[l:]))])', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\nvis = [0]*N\np = 1\nTown = []\n\nwhile vis[p-1] == 0:\n Town.append(p)\n vis[p-1] = 1\n p = A[p-1]\n\nl = Town.index(p)\n\nif K < len(Town):\n print(Town[K])\nelse:\n print(Town[l + (K-l)%(len(Town[l:]))])']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s679146875', 's927191568', 's906711907']
|
[32332.0, 32380.0, 32364.0]
|
[83.0, 144.0, 150.0]
|
[406, 272, 275]
|
p02684
|
u090649502
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["#!/usr/bin/env python3\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools\ndef main(n, k, a):\n ck=[-1]*n\n tak=0\n c=0\n ck[0]=c\n for i in range(n):\n c+=1\n tak=a[tak]-1\n if ck[tak]!=-1:\n loop=c-ck[tak]\n lps=ck[tak]\n break\n ck[tak]=c\n print(ck, loop, lps)\n\n tak=0\n for i in range((k-lps)%(loop)+lps):\n tak=a[tak]-1\n\n print(tak+1)\n\n\nif __name__ == '__main__':\n n,k=map(int, input().split())\n a=list(map(int, input().split()))\n main(n, k, a)\n", "#!/usr/bin/env python3\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools\ndef main(n, k, a):\n ck=[-1]*n\n tak=0\n c=0\n ck[0]=c\n for i in range(n):\n c+=1\n tak=a[tak]-1\n if ck[tak]!=-1:\n loop=c-ck[tak]\n lps=ck[tak]\n break\n ck[tak]=c\n\n tak=0\n for i in range(min(k, (k-lps)%(loop)+lps)):\n tak=a[tak]-1\n\n print(tak+1)\n\n\nif __name__ == '__main__':\n n,k=map(int, input().split())\n a=list(map(int, input().split()))\n main(n, k, a)\n"]
|
['Wrong Answer', 'Accepted']
|
['s450947352', 's975671665']
|
[32364.0, 32312.0]
|
[218.0, 169.0]
|
[558, 541]
|
p02684
|
u091489347
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["import sys\nn, k = map(int, input().split())\nl = list(map(int, input().split()))\ncount = 0\nli = [0 for _ in range(n)]\nb = 1\nfor i in range(1,n + 1):\n print(b)\n if li[b-1] != 0:\n break\n li[b-1] = i\n b = l[b-1]\n count += 1\n# print('count',count)\n\n\nd = count - li[b-1] + 1\nintercep = li[b-1] -1\nprint('d', d, 'intercep', intercep)\nif k <= intercep:\n b = 1\n for i in range(k):\n b = l[b-1]\n print(b)\n sys.exit()\n \nmod = (k - intercep) % d\nb = 1\nfor i in range(intercep + mod):\n print('b',b)\n b = l[b-1]\nprint(b)", "import sys\nn, k = map(int, input().split())\nl = list(map(int, input().split()))\ncount = 0\nli = [0 for _ in range(n)]\nb = 1\nfor i in range(1,n + 1):\n# print(b)\n if li[b-1] != 0:\n break\n li[b-1] = i\n b = l[b-1]\n count += 1\n# print('count',count)\n\n\nd = count - li[b-1] + 1\nintercep = li[b-1] -1\n# print('d', d, 'intercep', intercep)\nif k <= intercep:\n b = 1\n for i in range(k):\n b = l[b-1]\n print(b)\n sys.exit()\n \nmod = (k - intercep) % d\nb = 1\nfor i in range(intercep + mod):\n# print('b',b)\n b = l[b-1]\nprint(b)"]
|
['Wrong Answer', 'Accepted']
|
['s319346380', 's437808300']
|
[32392.0, 32332.0]
|
[302.0, 182.0]
|
[559, 565]
|
p02684
|
u095094246
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import sys\nn,k=map(int,input().split())\na=[int(x) for x in input().split()]\nvis={0:0}\nnow=0\nfor i in range(1,k+1):\n now=a[now]-1\n if now in vis:\n bgn=vis.index(now)\n print(vis[bgn+((k-bgn)%(len(vis)-bgn))]+1)\n sys.exit()\n else:\n vis[i]=now\nprint(vis[-1]+1)\n', 'import sys\nn,k=map(int,input().split())\na=[int(x) for x in input().split()]\nvis_ti=[-1]*n\nvis_at=[0]\nnow=0\nfor i in range(1,k+1):\n now=a[now]-1\n if vis_ti[now]>=0:\n bgn=vis_ti[now]\n print(vis_at[bgn+(k-bgn)%(i-bgn)]+1)\n sys.exit()\n vis_ti[now]=i\n vis_at.append(now)\nprint(vis_at[-1]+1)\n\n']
|
['Runtime Error', 'Accepted']
|
['s318437372', 's280880881']
|
[33432.0, 32332.0]
|
[102.0, 148.0]
|
[272, 300]
|
p02684
|
u102218630
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\ngenzaichi=1\ncount=0\nfor i in range(K):\n genzaichi=A[genzaichi-1]\n count += 1\n if genzaichi == 1:\n break\n\nK=K%count\nprint(count)\n\nfor i in range(K):\n genzaichi=A[genzaichi-1]\n\n\nprint(genzaichi)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\ngenzaichi=1\nrireki=[]\nhoumon=[0]*(N+1)\nflag=0\n\nfor i in range(1,K+1):\n genzaichi=A[genzaichi-1]\n if genzaichi not in rireki:\n houmon[genzaichi]=i\n rireki.append(genzaichi)\n else:\n roop_from=genzaichi\n x=houmon[roop_from]\n roop=i-x\n flag=1\n break\n\nprint("now")\nprint(x)\nprint(roop)\nprint(roop_from)\nprint(flag)\n\ngenzaichi=1\nif flag==1:\n K=K-(((K-x)//roop)-1)*roop\n print(K)\n\nfor i in range(K):\n genzaichi=A[genzaichi-1]\n\nprint(genzaichi)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\ngenzaichi=1\nrireki=set()\nhoumon=[0]*(N+1)\nflag=0\n\nfor i in range(1,K+1):\n genzaichi=A[genzaichi-1]\n if genzaichi not in rireki:\n houmon[genzaichi]=i\n rireki.append(genzaichi)\n else:\n roop_from=genzaichi\n x=houmon[roop_from]\n roop=i-x\n flag=1\n break\n\nif flag==0:\n print(genzaichi)\nelse:\n genzaichi=roop_from\n K=(K-x)-((K-x)//roop)*roop\n for i in range(K):\n genzaichi=A[genzaichi-1]\n print(genzaichi)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\ngenzaichi=1\nrireki=set()\nhoumon=[0]*(N+1)\nflag=0\n\nfor i in range(1,K+1):\n genzaichi=A[genzaichi-1]\n if genzaichi not in rireki:\n houmon[genzaichi]=i\n rireki.add(genzaichi)\n else:\n roop_from=genzaichi\n x=houmon[roop_from]\n roop=i-x\n flag=1\n break\n\nif flag==0:\n print(genzaichi)\nelse:\n genzaichi=roop_from\n K=(K-x)-((K-x)//roop)*roop\n for i in range(K):\n genzaichi=A[genzaichi-1]\n print(genzaichi)']
|
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s011673534', 's687787683', 's688430168', 's927862888']
|
[32272.0, 32396.0, 32380.0, 36136.0]
|
[2206.0, 2206.0, 68.0, 167.0]
|
[274, 566, 541, 538]
|
p02684
|
u102367647
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["from sys import stdin\nimport math\n\n\ndef main():\n n, k = list(map(int, input().split()))\n A = list(map(int, stdin.readline().split()))\n roots = []\n roots.append(A)\n maxLoop = math.ceil(math.log(k)/math.log(2))\n for _ in range(1, maxLoop):\n roots_tmp = [None] * n\n for j in range(n):\n roots_tmp[j] = roots[-1][roots[-1][j]-1]\n roots.append(roots_tmp)\n\n position = 1\n for i in range(maxLoop+1):\n if k & (1 << (maxLoop-i)):\n position = roots[-1-i][position-1]\n\n print(position)\n\nif __name__ == '__main__':\n main()\n", "from sys import stdin\n\n\ndef main():\n n, k = list(map(int, input().split()))\n A = list(map(int, stdin.readline().split()))\n roots = [1]\n position = 0\n for _ in range(n):\n position = A[roots[-1]-1]\n A[roots[-1]-1] = - position\n if position < 0:\n break\n roots.append(position)\n\n x = roots.index(-position)\n y = len(roots) - x\n\n if k <= x:\n print(roots[k])\n elif k > x:\n print(roots[x + ((k-x) % y)])\n\n\nif __name__ == '__main__':\n main()\n"]
|
['Runtime Error', 'Accepted']
|
['s932181638', 's170003627']
|
[110476.0, 31328.0]
|
[2209.0, 154.0]
|
[590, 517]
|
p02684
|
u105302073
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['6 727202214173249351\n6 5 2 5 3 2\nn, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\ns = []\no = [-1] * (n + 1) \nc, l = 1, 0 \n\nv = 1\nwhile o[v] == -1:\n o[v] = len(s)\n s.append(v)\n v = a[v-1]\nc = len(s) - o[v]\nl = o[v]\n\nif k < l:\n print(s[k])\nelse:\n k -= l\n k %= c\n print(s[l + k])\n', 'n, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\ns = []\no = [-1] * (n + 1) \nc, l = 1, 0 \n\nv = 1\nwhile o[v] == -1:\n o[v] = len(s)\n s.append(v)\n v = a[v-1]\nc = len(s) - o[v]\nl = o[v]\n\nif k < l:\n print(s[k])\nelse:\n k -= l\n k %= c\n print(s[l + k])\n']
|
['Runtime Error', 'Accepted']
|
['s481199806', 's401443643']
|
[9012.0, 32336.0]
|
[24.0, 168.0]
|
[402, 369]
|
p02684
|
u112114596
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K=map(int, input().split())\nA=list(map(int, input().split()))\n\nloopcount=0\ntmpPoint=1\nvis={1:0}\nfor i in range(N):\n Next=A[tmpPoint-1]\n if Next in vis:\n startat=i\n #print(startat)\n #print(tmpPoint)\n #print(vis)\n #print(Next)\n #print(vis[Next]+1)\n loopcount=i - vis[Next]+1\n break\n vis[Next]=i+1\n tmpPoint=Next\n\nprint(loopcount)\nif loopcount==0:\n print(tmpPoint)\n exit()\n\nnokori=(K-startat) % loopcount\n\nprint(startat)\nprint(nokori)\nprint(loopcount)\n\ntmpPoint=1\nfor i in range(startat+nokori):\n Next=A[tmpPoint-1]\n tmpPoint=Next\nprint(tmpPoint)', 'N,K=map(int, input().split())\nA=list(map(int, input().split()))\n\nloopcount=0\ntmpPoint=1\nvis={1:0}\nfor i in range(N):\n Next=A[tmpPoint-1]\n if Next in vis:\n startat=i\n #print(startat)\n #print(tmpPoint)\n #print(vis)\n #print(Next)\n #print(vis[Next]+1)\n loopcount=i - vis[Next]+1\n break\n vis[Next]=i+1\n tmpPoint=Next\n\nif loopcount==0:\n print(tmpPoint)\n exit()\n\nnokori=(K-startat) % loopcount\n\nprint(startat)\nprint(nokori)\nprint(loopcount)\n\ntmpPoint=1\nfor i in range(startat+nokori):\n Next=A[tmpPoint-1]\n tmpPoint=Next\nprint(tmpPoint)', 'N,K=map(int, input().split())\nA=list(map(int, input().split()))\n\nloopcount=0\ntmpPoint=1\nvis={1:0}\nfor i in range(N):\n Next=A[tmpPoint-1]\n if Next in vis:\n startat=i\n #print(startat)\n #print(tmpPoint)\n #print(vis)\n #print(Next)\n #print(vis[Next]+1)\n loopcount=i - vis[Next]+1\n break\n vis[Next]=i+1\n tmpPoint=Next\n\nif loopcount==0:\n print(tmpPoint)\n exit()\nif startat+loopcount < K:\n nokori=(K-startat) % loopcount\n\ntmpPoint=1\nfor i in range(startat+nokori):\n Next=A[tmpPoint-1]\n tmpPoint=Next\nprint(tmpPoint)', 'N,K=map(int, input().split())\nA=list(map(int, input().split()))\n\nloopcount=0\ntmpPoint=1\nvis={1:0}\nfor i in range(N):\n Next=A[tmpPoint-1]\n if Next in vis:\n startat=i\n #print(startat)\n #print(tmpPoint)\n #print(vis)\n #print(Next)\n #print(vis[Next]+1)\n loopcount=i - vis[Next]+1\n break\n vis[Next]=i+1\n tmpPoint=Next\n\nif loopcount==0:\n print(tmpPoint)\n exit()\nif startat+nokori < K:\n nokori=(K-startat) % loopcount\n\ntmpPoint=1\nfor i in range(startat+nokori):\n Next=A[tmpPoint-1]\n tmpPoint=Next\nprint(tmpPoint)', 'N,K=map(int, input().split())\nA=list(map(int, input().split()))\n\nloopcount=0\ntmpPoint=1\nvis={1:0}\nfor i in range(N):\n Next=A[tmpPoint-1]\n if Next in vis:\n startat=i\n #print(startat)\n #print(tmpPoint)\n #print(vis)\n #print(Next)\n #print(vis[Next]+1)\n loopcount=i - vis[Next]+1\n break\n vis[Next]=i+1\n tmpPoint=Next\n\nif loopcount==0:\n print(tmpPoint)\n exit()\nif startat+loopcount < K:\n nokori=(K-startat) % loopcount\n K=startat+nokori\n\ntmpPoint=1\nfor i in range(K):\n Next=A[tmpPoint-1]\n tmpPoint=Next\nprint(tmpPoint)']
|
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s654829406', 's878449014', 's886419443', 's894043829', 's862590476']
|
[38836.0, 38920.0, 38820.0, 38816.0, 38652.0]
|
[260.0, 250.0, 191.0, 193.0, 209.0]
|
[625, 608, 590, 587, 598]
|
p02684
|
u112629957
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int,input().split())\nls_pass = list(map(int,input().split()))\nls_pass.insert(0,0)\na=1\nb=0\nls_past=[1]\nfor i in range(1,N+1):\n b=a\n a=ls_pass[a]\n if b==a:\n print(a)\n break\n elif a in ls_past:\n c=ls_past.index(a)\n ls_cicle=ls_past[c:i]\n print(ls_cicle[(K-i)%(i-c)])\n break\n elif i=K:\n print(a)\n break\n else:\n ls_past.append(a)', 'N, K = map(int,input().split())\nls_pass = [0]+list(map(int,input().split()))\na=1\nb=0\n\nls=["ンゴ"]+[0]+["ンゴ"]*(N-1)\nls_past=[1]\nfor i in range(1,N*3):\n b=a\n a=ls_pass[a]\n if ls[a]!="ンゴ":\n ls_cicle=ls_past[ls[a]:i]\n print(ls_cicle[(K-i)%len(ls_cicle)])\n break\n elif i==K:\n print(a)\n break \n else:\n ls_past.append(a)\n ls[a]=i']
|
['Runtime Error', 'Accepted']
|
['s953377179', 's766951067']
|
[9028.0, 32388.0]
|
[25.0, 145.0]
|
[368, 359]
|
p02684
|
u114641312
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['# from math import factorial,sqrt,ceil,gcd\n# from itertools import permutations,combinations,combinations_with_replacement\n# from collections import deque,Counter\n# import re\n\n# from decimal import Decimal, getcontext\n\n# # eps = Decimal(10) ** (-100)\n\n# import numpy as np\n# import networkx as nx\n# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson\n# from scipy.sparse import csr_matrix\n# from scipy.special import comb\n\n\nN,K = map(int,input().split())\nlisA = [0] + list(map(int,input().split()))\n# arrA = np.array(input().split(),dtype=np.int64)\n\nchecked = {1:0}\nroopstnum = 0\ni = 1\nfor n in range(1,N+2):\n if not lisA[i] in checked:\n checked[lisA[i]] = n\n i = lisA[i]\n else:\n roopstnum = lisA[i]\n roopstidx = checked[roopstnum]\n rooplen = n - roopstidx\n break\n\nprint(roopstnum,rooplen,roopstidx,checked)\nwarukazu = rooplen\nfor k,v in checked.items():\n if (K-roopstidx) % warukazu == v - roopstidx:\n ans = k\nprint(ans)\n\n# for row in board:\n\n# print("{:.10f}".format(ans))\n# print("{:0=10d}".format(ans))\n', '# from math import factorial,sqrt,ceil,gcd\n# from itertools import permutations,combinations,combinations_with_replacement\n# from collections import deque,Counter\n# import re\n\n# from decimal import Decimal, getcontext\n\n# # eps = Decimal(10) ** (-100)\n\n# import numpy as np\n# import networkx as nx\n# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson\n# from scipy.sparse import csr_matrix\n# from scipy.special import comb\n\n\nN,K = map(int,input().split())\nlisA = [0] + list(map(int,input().split()))\n# arrA = np.array(input().split(),dtype=np.int64)\n\nif K<=N:\n i = K\n j = 1\n while i > 0:\n j = lisA[j]\n i -= 1\n print(j)\n exit()\n\nchecked = {1:0}\nroopstnum = 0\ni = 1\nfor n in range(1,N+2):\n if not lisA[i] in checked:\n checked[lisA[i]] = n\n i = lisA[i]\n else:\n roopstnum = lisA[i]\n roopstidx = checked[roopstnum]\n rooplen = n - roopstidx\n break\n\n\nwarukazu = rooplen\nfor k,v in checked.items():\n if (K-roopstidx) % warukazu == v - roopstidx:\n ans = k\nprint(ans)\n\n# for row in board:\n\n# print("{:.10f}".format(ans))\n# print("{:0=10d}".format(ans))\n']
|
['Wrong Answer', 'Accepted']
|
['s228353571', 's907476543']
|
[40044.0, 32376.0]
|
[210.0, 182.0]
|
[1400, 1508]
|
p02684
|
u116038906
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['\nfrom collections import Counter\nfrom copy import deepcopy\nimport sys\ninput = sys.stdin.readline\nN,K = (int(x) for x in input().split())\nA = list(map(int, input().split()))\nconnection ={}\nfor i,v in enumerate(A):\n connection[i+1] =v \n\n\npassed=[1]\nnex =connection[1]\nlap =[]\nlap_num =0\npass_set =set()\nfor i in range(1,N+1):\n passed.append(nex)\n if nex not in pass_set:\n pass_set.add(nex)\n nex =connection[nex]\n else:\n #lap =deepcopy(passed)\n break\n\nindx_s =passed.index(nex) +1\nindx_f =len(passed)\nlap_num =indx_f -indx_s\n\nif indx_f < K:\n mod =(K -indx_s) % lap_num\n ans =passed[indx_s +mod]\nelse:\n ans =passed[K]\nprint(ans)', '\nN,K = (int(x) for x in input().split())\nA = list(map(int, input().split()))\n\nconnection ={i:0 for i in range(1,N+1)}\nfor i in range(1,N+1):\n connection[i] =A[i-1]\n\npassed =[1]\npassed_set =set(passed)\nintersection =0\nnext =connection[1]\n#count_intersection =[]\n#count_loop =0\nfor i in range(1,N+1): \n if next not in passed_set:\n passed.append(next)\n passed_set.add(next)\n next =connection[next]\n else:\n intersection =next\n break\n\nloop_s =passed.index(intersection)\nloop_f =len(passed) \nloop_num =loop_f -loop_s\n\n\nans =0\nif K < loop_f:\n ans =passed[K]\nelse:\n K2 =K -loop_s\n q,mod =divmod(K2,loop_num)\n ans =passed[loop_s +mod]\nprint(ans)']
|
['Runtime Error', 'Accepted']
|
['s655325823', 's794268662']
|
[49864.0, 49268.0]
|
[254.0, 282.0]
|
[747, 924]
|
p02684
|
u118887775
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['\ndef parse():\n N, K = map(int, input().split(" "))\n A = []\n for a in input().split(" "):\n A.append(int(a) - 1)\n return N, K, A\n\ndef fast_mod(x, N):\n return (x * N) >> 32\n\ndef main():\n N, K, A = parse()\n # print(N, K, A)\n\n \n route = []\n next_town = A[0]\n town = 0\n while not (next_town in route): \n route.append(town)\n next_town = A[town]\n town = next_town\n once_route = route[:route.index(next_town)]\n loop_route = route[route.index(next_town):]\n # print("once_route:", once_route)\n # print("loop_route:", loop_route)\n \n # print([town + 1 for town in route])\n # print("K %% len(loop_route):", K % len(loop_route))\n # print(route[K % len(loop_route) + len(once_route)] + 1)\n print(route[fast_mod(K, len(loop_route))])\n # print(route[K % len(loop_route) + len(once_route)] + 1)\n\nif __name__ == "__main__":\n main()\n', '\ndef parse():\n N, K = map(int, input().split(" "))\n A = []\n for a in input().split(" "):\n A.append(int(a) - 1)\n return N, K, A\n\ndef fast_pow(x, n):\n \n if n == 0:\n return 1\n\n K = 1\n while n > 1:\n if n % 2 != 0:\n K *= x\n x *= x\n n //= 2\n\n return K * x\n\ndef fast_mod(x, N):\n # return x % N\n if N % 2 == 0:\n return x & (N - 1)\n else:\n return x % N\n\ndef main():\n N, K, A = parse()\n # print(N, K, A)\n\n \n town = 0\n route = [0]\n loop_start_index = None\n i = 0\n visited = [False for i in range(N)]\n visited[0] = True\n for i in range(K):\n \n town = A[town]\n\n if visited[town]:\n \n loop_start_index = route.index(town)\n break\n\n visited[town] = True\n route.append(town)\n\n if loop_start_index == None:\n print(town + 1)\n else:\n loop_route = route[loop_start_index:]\n # print(loop_route, K, i)\n print(loop_route[(K - (i + 1)) % len(loop_route)] + 1)\n # print(loop_route[])\n # print(town)\n exit(0)\n\n \n route = []\n next_town = A[0]\n town = 0\n while not (next_town in route): \n route.append(town)\n next_town = A[town]\n town = next_town\n once_route = route[:route.index(next_town)]\n loop_route = route[route.index(next_town):]\n # print("once_route:", once_route)\n # print("loop_route:", loop_route)\n \n \n\n # print([town + 1 for town in route])\n # print("K %% len(loop_route):", K % len(loop_route))\n # print(route[K % len(loop_route) + len(once_route)] + 1)\n if K >= len(route) and len(once_route) > 0:\n # print("loop")\n loop_K = K - len(route)\n print(loop_route[fast_mod(loop_K, len(loop_route))] + 1)\n # print(loop_route[loop_K % len(loop_route)] + 1)\n else:\n # print("normal")\n \n \n # print("K %% len(route):", K % len(route))\n print(route[fast_mod(K, len(route))] + 1)\n # print(route[K % len(route)] + 1)\n\nif __name__ == "__main__":\n main()\n']
|
['Runtime Error', 'Accepted']
|
['s012940021', 's329817513']
|
[32224.0, 32288.0]
|
[2206.0, 136.0]
|
[894, 2087]
|
p02684
|
u119982001
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int,input().split())\n# a = list(map(int, input().split()))\n\nD = 60\nMAX_N = 200005\nto[D][MAX_N]\n\nfor i in range(n):\n to[0][i] = int(input())\n to[0][i] -= 1\n\nfor i in range(i, D-1):\n for j in range(n):\n to[i+1][j] = to[i][to[i][j]]\n\nv = 0\nfor i in range(D-1,0):\n l = 1<<i\n if (l <= k):\n v = to[i][v]\n k -= l\n\nprint(v+1)\n', 'n, k = map(int,input().split())\na = list(map(int, input().split()))\n\nD = 60\nMAX_N = 200005\nto = [[0]*MAX_N]*D\n# to = [[0]*D]*MAX_N\n# to = [D][MAX_N]\n\nfor i in range(n):\n to[0][i] = a[i]-1\n print(a[i]-1)\nfor i in range(D-1):\n for j in range(n):\n to[i+1][j] = to[i][to[i][j]]\n\nv = 0\nfor i in range(D-1):\n l = 1<<i\n if (l <= k):\n v = to[i][v]\n k -= l\n # print(i)\n \nprint(v+1)\n', 'n, k = map(int,input().split())\na = list(map(int, input().split()))\n\ntmp = a[0]\nk %= n\n\nfor i in range(k-1):\n tmp = a[tmp-1]\n \nprint(tmp)\n', 'n, k = map(int,input().split())\na = list(map(int, input().split()))\n\ns = []\nord = [-1]*(n+1)\nc = 1\nl = 0\n\n\nv = 1\nwhile (ord[v] == -1):\n ord[v] = len(s)\n s.append(v)\n v = a[v-1]\n \nc = len(s) - ord[v]\nl = ord[v]\n\n\nif (k < l): print(s[k])\nelse:\n k -= l\n k %= c\n print(s[l+k])']
|
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
|
['s033295822', 's547845283', 's900218225', 's357728104']
|
[9208.0, 32380.0, 32372.0, 32296.0]
|
[23.0, 2206.0, 109.0, 158.0]
|
[365, 415, 144, 293]
|
p02684
|
u123872895
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import collections\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nh = []\ni = 0\ns = 1\n\nans = 0\nwhile i < 2*n: \n g = a[s-1]\n h.append(g)\n if i == k - 1:\n ans = g\n sys.exit()\n else:\n s = g\n i+=1\nj = collections.Counter(h)\nm = j.most_common()[0][0]\nl = [i for i, x in enumerate(h) if x == m]\n\nd = (k - l[0]) % (l[1]-l[0])\nans = h[l[0]+d-1]\n\nprint(ans)\n\n ', 'n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ns = 1\ng = 0\ni = 1\nhistory = [s]\nflag = [False] * n\nflag[0] = True\n\nwhile True:\n g = a[s-1]\n if flag[g-1] == True:\n break\n else:\n flag[g-1] = True\n history.append(g)\n s = g\n i += 1\n\n\nx = history.index(g)\n\nif k < i:\n ans = history[k]\nelse:\n d = (k-x) % (i - x)\n\n ans = history[x + d]\n\nprint(ans)\n']
|
['Runtime Error', 'Accepted']
|
['s147178543', 's817999739']
|
[39240.0, 32380.0]
|
[373.0, 173.0]
|
[399, 423]
|
p02684
|
u126146165
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nG = {}\nfor i in range(1, n + 1):\n G.update({i: a[i - 1]})\n\nseen = [False] * (n + 1)\npath = []\n\ndef dfs(graph, start):\n global return_ans\n seen[start] = True\n path.append(start)\n \n if seen[graph[start]]:\n return_ans = graph[start]\n else:\n dfs(graph, graph[start])\n \n return return_ans\n\npoint = dfs(G, 1)\nlong = len(path)\nm = path.index(point)\nans = (k + 1) % (long - m)\npath = path[m:]\nprint(path[ans])\n', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nG = {}\nfor i in range(1, n + 1):\n G.update({i: a[i - 1]})\n\nseen = [False] * (n + 1)\npath = []\n\ndef dfs(graph, start):\n global return_ans\n seen[start] = True\n path.append(start)\n \n if seen[graph[start]]:\n return graph[start]\n else:\n dfs(graph, graph[start])\n\n\npoint = dfs(G, 1)\nm = path.index(point)\n\nif m > k:\n print(path[k])\nelse:\n k -= m\n path = path[m:]\n k %= len(path)\n print(path[k])\n', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nG = {}\nfor i in range(1, n + 1):\n G.update({i: a[i - 1]})\n\nseen = [False] * (n + 1)\npath = [1]\n\ni = 1\nwhile True:\n seen[i] = True\n i = G[i]\n \n if seen[i]:\n break\n else:\n path.append(i)\n\nm = path.index(i)\n\nif m > k:\n print(path[k])\nelse:\n k -= m\n path = path[m:]\n k %= len(path)\n print(path[k])\n']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s768562071', 's916263263', 's967307512']
|
[38840.0, 39988.0, 40556.0]
|
[145.0, 145.0, 231.0]
|
[512, 508, 410]
|
p02684
|
u127873832
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\nroute = [1]\ndest = A[0]\nwhile dest not in route:\n route.append(dest)\n dest = A[dest - 1]\nind = route.index(dest)\ncycle = route[ind:]\nprint(ind, cycle)\nif k >= ind:\n ans = (k - ind) % len(cycle)\n print(cycle[ans])\nelse:\n print(route[k])', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\nroute = [1]\ndest = A[0]\ncheck = {i: False for i in range(n)}\nwhile not check[dest - 1]:\n check[dest - 1] = True\n route.append(dest)\n dest = A[dest - 1]\nind = route.index(dest)\ncycle = route[ind:]\nif k >= ind:\n ans = (k - ind) % len(cycle)\n print(cycle[ans])\nelse:\n print(route[k])']
|
['Wrong Answer', 'Accepted']
|
['s290721496', 's153543035']
|
[32376.0, 40704.0]
|
[2206.0, 208.0]
|
[319, 367]
|
p02684
|
u130387509
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['\nn,k = map(int,input().split())\na = list(map(int,input().split()))\n\n\ns = []\nord = [-1] * (n+1)\n\nv = 1\nc = 1\nl = 0\nwhile ord[v] == -1:\n ord[v] = len(s)\n s.append(v)\n v = a[v-1]\nc = len(s) - ord[v]\nl = ord[v]\n\nprint(s)\nprint(l+k)\nif l > k:\n print(s[k])\nelse:\n k -= l\n k %= c\n print(s[l+k])\n ', '\nn,k = map(int,input().split())\na = list(map(int,input().split()))\nfor i in range(n):\n a[i] -= 1\n\nloop = []\nloop_corr = []\nord = [-1]*n\ncurr = 0\nwhile ord[curr] == -1:\n ord[curr] = len(loop)\n loop.append(curr)\n curr = a[curr]\n \nloop_corr = loop[loop.index(curr):len(loop)]\n\n# print(loop)\n# print(loop_corr)\nif len(loop) > k:\n print(loop[k]+1)\nelse:\n diff = k - len(loop) + 1\n mod = (diff % len(loop_corr)) -1\n # print(diff)\n # print(mod)\n print(loop_corr[mod]+1)\n \n ']
|
['Wrong Answer', 'Accepted']
|
['s032135097', 's821660355']
|
[32244.0, 32376.0]
|
[166.0, 170.0]
|
[313, 513]
|
p02684
|
u130900604
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['# coding: utf-8\n# Your code here!\n# from collections import Counter\n# from functools import *\n\ndef LI():\n return list(map(int,input().split()))\n\nn,k=LI()\na=[q-1 for q in LI()]\n\nvisited=[-1]*n\nnow=0\nvisited[now]=0\n\nif k<=2*10**5:\n for i in range(k):\n nxt=a[now]\n now=nxt\n print(now)\n exit()\n\nfor i in range(k):\n nxt=a[now]\n now=nxt\n if visited[nxt]==-1:\n visited[nxt]=i\n else:\n m=i-visited[nxt]\n break\nnow=0\nfor i in range(k%m+m):\n nxt=a[now]\n now=nxt\nprint(now)\nexit()\n\n', '# coding: utf-8\n# Your code here!\n# from collections import Counter\n# from functools import *\n\ndef LI():\n return list(map(int,input().split()))\n\nn,k=LI()\na=[q-1 for q in LI()]\n\nvisited=[-1]*(n+10)\nnow=0\nvisited[now]=0\n\nif k<=2*10**5:\n for i in range(k):\n nxt=a[now]\n now=nxt\n print(now)\n exit()\n\nfor i in range(k):\n nxt=a[now]\n if visited[nxt]==-1:\n visited[nxt]=i\n else:\n m=i-visited[nxt]\n break\nfor i in range(k%m+m):\n nxt=a[now]\n now=nxt\nprint(now)\nexit()\n\n', 'n,k,*a=map(int,open(0).read().split())\n\nnow=1\nif k<=n:\n for i in range(k):\n now=a[now-1]\n print(now)\n exit()\n\nvisited=[-1]*n\nfor i in range(4*10**5):\n now=a[now-1]\n if visited[now-1]==-1:\n visited[now-1]=i\n else:\n c,d=visited[now-1],i\n break\n\nk=(k-c)%(d-c)+c\nfor i in range(k+c):\n now=a[now-1]\nprint(now)', '# coding: utf-8\n# Your code here!\n# from collections import Counter\n# from functools import *\n\ndef LI():\n return list(map(int,input().split()))\n\nn,k=LI()\na=LI()\nb=[]\nvisited=[-1]*n\n\nnow=1\nfor i in range(k):\n nxt=a[now-1]\n b.append(nxt)\n if visited[nxt-1]==-1:\n visited[nxt-1]=i+1\n else:\n mod=(visited[nxt-1],i+1)\n break\n now=nxt\n\nml,mr=mod\nk=(k-ml)%(mr-ml)+ml\nprint(k)\n\nprint(b[k-1])', 'n,k,*a=map(int,open(0).read().split())\n\nnow=1\nif k<=n:\n for i in range(k):\n now=a[now-1]\n print(now)\n exit()\n\nvisited=[False]*n\nvisited[now-1]=-1\nfor i in range(4*10**5):\n now=a[now-1]\n if visited[now-1]==False:\n visited[now-1]=i\n else:\n c,d=visited[now-1],i\n break\n\nk=(k-c)%(d-c)+c\n#while k<n:\n# k+=(d-c)\nnow=1\nfor i in range(k):\n now=a[now-1]\nprint(now)\n', 'n,k,*a=map(int,open(0).read().split())\n\nnow=1\nif k<=n:\n for i in range(k):\n now=a[now-1]\n print(now)\n exit()\n\nvisited=[False]*n\nvisited[now-1]=-1\nfor i in range(4*10**5):\n now=a[now-1]\n if visited[now-1]==False:\n visited[now-1]=i\n else:\n c,d=visited[now-1],i\n break\n\nk=(k-c)%(d-c)+c\nwhile k<n:\n k+=(d-c)\nnow=1\nfor i in range(k):\n now=a[now-1]\nprint(now)']
|
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
|
['s004299631', 's094029288', 's348166166', 's540663181', 's848414512', 's605646596']
|
[32380.0, 32380.0, 31788.0, 32272.0, 31808.0, 31812.0]
|
[196.0, 123.0, 167.0, 148.0, 152.0, 157.0]
|
[535, 522, 346, 422, 399, 396]
|
p02684
|
u131638468
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(n):\n a[i]-=1\nvisit=[False for i in range(n)]\nvisit[0]=True\nlooplist=[False for i in range(n)]\nmark=-1\ni=0\nnum=0\nloop=0\ncount=0\nwhile True:\n num+=1\n i=a[i]\n if mark<0 and visit[i]:\n mark=a[i]\n else:\n visit[i]=True\n if mark>-1 and looplist[i]:\n count=num-loop*2\n break\n elif mark>-1:\n loop+=1\n looplist[i]=True\nif k<count:\n pass\nelse:\n k-=count\n k%=loop\n k+=count\nans=0\nfor i in range(k):\n ans=a[ans]\nprint(ans+1)\nprint(count,loop)', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(n):\n a[i]-=1\nvisit=[False for i in range(n)]\nvisit[0]=True\nlooplist=[False for i in range(n)]\nmark=-1\ni=0\nnum=0\nloop=0\ncount=0\nwhile True:\n num+=1\n i=a[i]\n if mark<0 and visit[i]:\n mark=a[i]\n else:\n visit[i]=True\n if mark>-1 and looplist[i]:\n count=num-loop*2\n break\n elif mark>-1:\n loop+=1\n looplist[i]=True\nif k < count:\n pass\nelse:\n k-=count\n k%=loop\n k+=count\nans=0\nfor i in range(k):\n ans=a[ans]\nprint(ans+1)']
|
['Wrong Answer', 'Accepted']
|
['s836345020', 's933790157']
|
[32240.0, 32408.0]
|
[309.0, 319.0]
|
[536, 520]
|
p02684
|
u133936772
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['f=lambda:map(int,input().split())\nn,k=f()\na=list(f())\nlv=[-1]*n\nlv[0]=0\np=0\nfor i in range(n):\n t=a[p]-1\n if lv[t]>=0:\n l,r=lv[t],i+1\n break\n lv[t]=i+1\n p=t\nprint(lv,l,r)\nd,m=divmod(k-l,r-l)\nprint(d,m)\nprint(lv.index(l+(k-l)%(r-l) if k>l else k)+1)', 'n,k,*a=map(int,open(0).read().split())\nv=[-1]*n\nt=c=0\nwhile v[t]<0: v[t]=c; c+=1; t=a[t]-1\nl=v[t]\nc-=l\nprint(v.index(min(k,l+(k-l)%c))+1)']
|
['Wrong Answer', 'Accepted']
|
['s412088352', 's593864823']
|
[32376.0, 31776.0]
|
[210.0, 142.0]
|
[258, 137]
|
p02684
|
u135961419
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = list(map(int,input().split()))\na = list(map(int,input().split()))\n \nposition = 1\nexp = [1]\ncount = 0\n \nif n >= k:\n for i in range(k):\n position = a[position - 1]\n print(position)\nelse:\n for i in range(k):\n position = a[position - 1]\n count += 1\n if position in exp:\n exp.append(position)\n else:\n break\n init = exp.index(position)\n res = (k - init) % (count - init)\n print(exp[init + res])', 'n, k = list(map(int,input().split()))\na = list(map(int,input().split()))\n \nposition = 1\nexp1 = [0] * n\nexp1[0] = 1\nexp = [1]\ncount = 0\n \nif n >= k:\n for i in range(k):\n position = a[position - 1]\n print(position)\nelse:\n for i in range(k):\n position = a[position - 1]\n count += 1\n if exp1[position - 1] == 0:\n exp.append(position)\n exp1[position - 1] += 1\n else:\n break\n init = exp.index(position)\n res = (k - init) % (count - init)\n print(exp[init + res])']
|
['Runtime Error', 'Accepted']
|
['s921376131', 's864888420']
|
[99740.0, 32244.0]
|
[2209.0, 143.0]
|
[426, 491]
|
p02684
|
u139940813
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['\nN,K= map(int,input().split())\n\nA = [int(i) for i in input().split()]\n\n\ndef has_duplicates(seq):\n return len(seq) == len(set(seq))\n\n\nwarp = [1]\na = 1\n\n\nwhile has_duplicates(warp):\n a = A [a - 1]\n warp.append(a)\n \n if len(warp) == K +1:\n print(warp[K])\n break\n\nl = [i for i, x in enumerate(warp) if x == a]\n\n\nwidth = l[1] - l[0]\n\n\nd = (K - l[0]) % (l[1]-l[0])\n\n\nprint(d + l[0])', '\nN,K= map(int,input().split())\n\nA = [int(i)-1 for i in input().split()]\njudge = [-1] * N\njudge[0] = 0\n\na = 0\n\nstep = 1\n\nwhile step != K +1:\n \n a = A[a]\n if judge[a] > -1:\n break\n \n judge[a] = step\n step = step + 1\n\nif step == K +1:\n print(a+1)\n \nelse:\n width = step - judge[a]\n s =(K - judge[a]) % width\n print(judge.index(judge[a]+s)+1)']
|
['Runtime Error', 'Accepted']
|
['s765829373', 's061231935']
|
[33120.0, 32340.0]
|
[2206.0, 164.0]
|
[713, 532]
|
p02684
|
u143212659
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n\n R = [False] * (N + 1)\n D = []\n\n p = 1\n\n while True:\n if R[p]:\n break\n D.append(p)\n R[p] = True\n p = A[p - 1]\n\n m = D.index(p)\n c = len(D) - m\n\n if K <= m:\n print(D[K])\n else:\n print(D[m + K - m] % c)\n\n\nif __name__ == "__main__":\n main()\n', '#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n\n R = [False] * (N + 1)\n D = []\n\n p = 1\n\n while True:\n if R[p]:\n break\n D.append(p)\n R[p] = True\n p = A[p - 1]\n\n m = D.index(p)\n c = len(D) - m\n\n if K <= m:\n print(D[K])\n else:\n print(D[m + (K - m) % c])\n\n\nif __name__ == "__main__":\n main()\n']
|
['Runtime Error', 'Accepted']
|
['s669353976', 's734861200']
|
[32248.0, 32388.0]
|
[110.0, 135.0]
|
[456, 458]
|
p02684
|
u146307964
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nAlist = list(map(int, input().split()))\n\n\nloop_num = 2 * 10 ** 5\nloop_start_point = -1\npoint = 1\ncount_list = [-1] * N\n\nfor i in range(K):\n #print("point:", point)\n count_list[point - 1] = i\n nextPoint = Alist[point - 1]\n\n if count_list[nextPoint - 1] != -1:\n loop_start_point = nextPoint\n loop_num = i - count_list[loop_start_point - 1] + 1\n break\n \n point = nextPoint\n\nif loop_start_point == -1:\n #print(point)\nelse:\n point = loop_start_point\n progress_num = (K - count_list[loop_start_point-1]) % loop_num\n for i in range(progress_num):\n point = Alist[point - 1]\n #print("pro:", progress_num)\n #print("ls:", loop_start_point)\n #print("ln:", loop_num)\n print(point)', 'N, K = map(int, input().split())\nAlist = list(map(int, input().split()))\n\n\nloop_num = 2 * 10 ** 5\nloop_start_index = 0\npoint = 1\nroute_list = [-1] * N\n\nfor i in range(K):\n point = Alist[point - 1]\n\n if route_list[point - 1] != -1:\n loop_start_index = route_list[point - 1]\n loop_num = i + 1 - loop_start_index\n break\n\n route_list[point - 1] = i\n\nprint(route_list[loop_start_index + ((K-loop_start_index) % loop_num)])', 'N, K = map(int, input().split())\nAlist = list(map(int, input().split()))\n\n\nloop_num = 2 * 10 ** 5\nloop_start_point = -1\npoint = 1\ncount_list = [-1] * N\n\nfor i in range(K):\n #print("point:", point)\n count_list[point - 1] = i\n nextPoint = Alist[point - 1]\n\n if count_list[nextPoint - 1] != -1:\n loop_start_point = nextPoint\n loop_num = i - count_list[loop_start_point - 1] + 1\n break\n \n point = nextPoint\n\nif loop_start_point == -1:\n print(point)\nelse:\n point = loop_start_point\n progress_num = (K - count_list[loop_start_point-1]) % loop_num\n for i in range(progress_num):\n point = Alist[point - 1]\n #print("pro:", progress_num)\n #print("ls:", loop_start_point)\n #print("ln:", loop_num)\n print(point)']
|
['Runtime Error', 'Wrong Answer', 'Accepted']
|
['s845543403', 's942222907', 's705336719']
|
[9056.0, 32372.0, 32292.0]
|
[24.0, 145.0, 134.0]
|
[802, 480, 801]
|
p02684
|
u155687575
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['def main():\n n, k = map(int, input().split())\n lst = list(map(int, input().split()))\n ma = [l-1 for l in lst]\n \n visited = [False for _ in range(n)]\n history = []\n now = 0\n while True:\n if visited[now]:\n history.append(now)\n break\n \n visited[now] = True\n history.append(now)\n \n now = ma[now]\n if k <= len(history)-1:\n print(history[k])\n return\n \n last = history[-1]\n for i in range(n):\n if history[i] == last:\n roopstart = i\n break\n syokilst = history[:roopstart]\n rooplst = history[roopstart:]\n syokilen = len(syokilst)\n rooplen = len(rooplst)\n resi = k - (syokilen-1)\n mod = resi%rooplen\n print(rooplst[mod])\n \nmain()', 'def main():\n n, k = map(int, input().split())\n lst = list(map(int, input().split()))\n ma = [l-1 for l in lst]\n \n visited = [False for _ in range(n)]\n history = []\n now = 0\n while True:\n if visited[now]:\n history.append(now)\n break\n \n visited[now] = True\n history.append(now)\n \n now = ma[now]\n if k <= len(history)-1:\n print(history[k] + 1)\n return\n \n last = history[-1]\n for i in range(n):\n if history[i] == last:\n roopstart = i\n break\n syokilst = history[:roopstart]\n rooplst = history[roopstart:-1]\n syokilen = len(syokilst)\n rooplen = len(rooplst)\n resi = k - syokilen\n mod = resi%(rooplen)\n print(rooplst[mod] + 1)\nmain()']
|
['Wrong Answer', 'Accepted']
|
['s430426775', 's341757664']
|
[32372.0, 32380.0]
|
[136.0, 142.0]
|
[790, 789]
|
p02684
|
u163320134
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\narr=list(map(int,input().split()))\nl=[-1]*(n+1)\ntmp=[]\npos=1\ncnt=0\nwhile 1:\n if l[pos]!=-1:\n if k<=l[pos]:\n print(tmp[k])\n else:\n print(tmp[l[pos]+(k+1)%(cnt-l[pos])])\n break\n l[pos]=cnt\n cnt+=1\n tmp.append(pos)\n pos=arr[pos-1]', 'n,k=map(int,input().split())\narr=list(map(int,input().split()))\nl=[-1]*(n+1)\ntmp=[]\npos=1\ncnt=0\nwhile 1:\n if l[pos]!=-1:\n t=cnt-l[pos]\n if k<cnt:\n print(tmp[k])\n else:\n print(tmp[l[pos]+(k-cnt)%t])\n break\n l[pos]=cnt\n cnt+=1\n tmp.append(pos)\n pos=arr[pos-1]']
|
['Wrong Answer', 'Accepted']
|
['s538144776', 's070648645']
|
[32360.0, 32380.0]
|
[180.0, 174.0]
|
[280, 284]
|
p02684
|
u163501259
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import sys\ninput = sys.stdin.readline\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n flag = True\n D = 0\n now = 1\n LOG = {}\n PATH = []\n for i in range(N):\n PATH.append(D)\n LOG.setdefault(D,i)\n\n if LOG[D] == i:\n D = A[D]-1\n continue\n else:\n print("break",D)\n start = D\n break\n # print(PATH, D)\n K = K%i\n LAST = PATH[LOG[D] + K] +1\n print(LAST)\n\n\n\nif __name__ == \'__main__\':\n main()', 'import sys\ninput = sys.stdin.readline\ndef main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n D = 1\n LOG = {}\n PATH = []\n for i in range(N):\n PATH.append(D)\n LOG.setdefault(D,i)\n\n if LOG[D] == i:\n D = A[D-1]\n # print(PATH,LOG, i)\n continue\n else:\n # print("break",D, i)\n break\n\n # if i-LOG[D] < K:\n if LOG[D] < K:\n K = (K-i)%(i-LOG[D])\n LAST = PATH[LOG[D]+K]\n else:\n LAST = PATH[K]\n print(LAST)\n\nif __name__ == \'__main__\':\n main()']
|
['Runtime Error', 'Accepted']
|
['s969047521', 's839857023']
|
[45512.0, 40008.0]
|
[178.0, 157.0]
|
[542, 595]
|
p02684
|
u164471280
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\n\ndef subtraction(x):\n return x - 1\nA = list(map(subtraction, A))\n\n\nR = [0]*n\nR[0] = 1\nROUTE = [0]\nt = A[0]\nwhile R[t] == 0:\n ROUTE.append(t)\n R[t] = 1\n t = A[t]\n print(ROUTE, R, t)\n\nx = ROUTE.index(t) \nlength = len(ROUTE) - x\nprint(ROUTE, length)\n\nif k < x:\n print(ROUTE[k]+1)\nelse:\n k = k - x\n s = k % length\n print(ROUTE[x + s]+1)', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\n\ndef subtraction(x):\n return x - 1\nA = list(map(subtraction, A))\n\n\nR = [0]*n\nR[0] = 1\nROUTE = [0]\nt = A[0]\nwhile R[t] == 0:\n ROUTE.append(t)\n R[t] = 1\n t = A[t]\n\nx = ROUTE.index(t) \nlength = len(ROUTE) - x\n\nif k < x:\n print(ROUTE[k]+1)\nelse:\n k = k - x\n s = k % length\n print(ROUTE[x + s]+1)']
|
['Wrong Answer', 'Accepted']
|
['s619885952', 's709120724']
|
[139828.0, 32276.0]
|
[2477.0, 162.0]
|
[555, 511]
|
p02684
|
u165436807
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int,input().split())\na = list(map(int, input().split()))\nt = [1]\nx = [0]*n\nx[0] = 1\ny = 1\nz = 0\nd = 0\nfor i in range(k):\n t.append(a[t[i]-1])\n if x[a[t[i]-1]-1] != 0:\n y = x[a[t[i]-1]-1]\n z = i+2\n b = [a[t[i]-1]]\n break\n else:\n x[a[t[i]-1]-1] += i+2\n z = i+2\n\nd = z-y\n\nprint(t)\nprint(x)\nprint(y)\nprint(z)\n\nif d != 0:\n r = (k - y) % d\nelse:\n r = k - y\n\nfor i in range(r+1):\n b.append(a[b[i]-1])\n\nprint(b[r+1])\n', 'n, k = map(int,input().split())\na = list(map(int, input().split()))\nt = [1]\nx = [0]*n\nx[0] = 1\ny = 1\nz = 0\nd = 0\nflag = False\nfor i in range(k):\n t.append(a[t[i]-1])\n if x[a[t[i]-1]-1] != 0:\n y = x[a[t[i]-1]-1]\n z = i+2\n b = [a[t[i]-1]]\n break\n else:\n x[a[t[i]-1]-1] += i+2\n z = i+2\n b = [a[t[i]-1]]\n if i == k - 1:\n flag = True\n\nif flag:\n print(a[t[k-1]-1])\n exit()\n\nd = z-y\n\n\nif d != 0:\n r = (k - y) % d\nelse:\n r = k - y\n\nfor i in range(r+1):\n b.append(a[b[i]-1])\n\nprint(b[r+1])\n']
|
['Runtime Error', 'Accepted']
|
['s037516469', 's887479454']
|
[32328.0, 32412.0]
|
[250.0, 243.0]
|
[480, 564]
|
p02684
|
u166340293
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\nflag=0\nnow=0\ni=0\ncount=0\nc=[0]*N\nr=[0]\nc[0]=1\nwhile flag==0:\n now=A[now]-1\n count+=1\n if count==K:\n flag=1\n elif c[now]==1:\n flag=2\n c[now]=1\n r.append(now)\nif flag==1:\n print(now+1)\nelse:\n o=[i for i, x in enumerate(r) if x == now]\n print(r[K%(o[1]-o[0])+o[0]+1]+1)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nflag=0\nnow=0\ni=0\ncount=0\nc=[0]*N\nr=[0]\nwhile flag==0:\n now=A[now]-1\n count+=1\n if count==K:\n flag=1\n elif c[now]==1:\n flag=2\n c[now]=1\n r.append(now)\nprint(r)\nif flag==1:\n print(now+1)\nelse:\n o=[i for i, x in enumerate(r) if x == now]\n print(A[r[K%(o[1]-o[0])]+o[0]-1])', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nflag=0\nnow=0\ni=0\ncount=0\nc=[0]*N\nr=[0]\nc[0]=1\nwhile flag==0:\n now=A[now]-1\n count+=1\n if count==K:\n flag=1\n elif c[now]==1:\n flag=2\n c[now]=1\n r.append(now)\nprint(r)\nif flag==1:\n print(now+1)\nelse:\n o=[i for i, x in enumerate(r) if x == now]\n print(o[0],o[1])\n print(r[(K-o[0])%(o[1]-o[0])+o[0]]+1)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nflag=0\nnow=0\ni=0\ncount=0\nc=[0]*N\nr=[0]\nc[0]=1\nwhile flag==0:\n now=A[now]-1\n count+=1\n if count==K:\n flag=1\n elif c[now]==1:\n flag=2\n c[now]=1\n r.append(now)\nprint(r)\nif flag==1:\n print(now+1)\nelse:\n o=[i for i, x in enumerate(r) if x == now]\n print(A[r[K%(o[1]-o[0])]+o[0]-1])', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nflag=0\nnow=0\ni=0\ncount=0\nc=[0]*N\nr=[0]\nc[0]=1\nwhile flag==0:\n now=A[now]-1\n count+=1\n if count==K:\n flag=1\n elif c[now]==1:\n flag=2\n c[now]=1\n r.append(now)\nif flag==1:\n print(now+1)\nelse:\n o=[i for i, x in enumerate(r) if x == now]\n print(r[(K-o[0])%(o[1]-o[0])+o[0]]+1)']
|
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
|
['s164514947', 's431057466', 's619263633', 's814373978', 's332120362']
|
[32168.0, 32388.0, 32300.0, 32380.0, 32384.0]
|
[142.0, 157.0, 182.0, 145.0, 139.0]
|
[343, 346, 376, 353, 348]
|
p02684
|
u169702930
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int, input().split())\na = list(map(int, input().split()))\nvisit = [-1 for i in range(n)]\nroot = []\nnow = 1\nlength = 0\nroot.append(now)\nif k > n:\n for i in range(n):\n if visit[now - 1] != 1:\n visit[now - 1] = 1\n now = a[now - 1]\n root.append(now)\n length += 1\n else:break\n start = 0\n for i in range(n):\n if root[i] == now:\n start = i\n break\n length -= start + 1\n k -= start\n k %= length\n ans = root[start]\n for i in range(k):\n ans = root[start + i]\n print(ans)\nelse:\n for i in range(k):\n now = a[now - 1]\n print(now)', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\nvisit = [-1 for i in range(n)]\nroot = []\nnow = 1\nlength = 0\nroot.append(now)\nif k > n:\n for i in range(n):\n if visit[now - 1] != 1:\n visit[now - 1] = 1\n now = a[now - 1]\n root.append(now)\n length += 1\n else:break\n start = 0\n for i in range(n):\n if root[i] == now:\n start = i\n break\n length -= start\n k -= start\n k %= length\n ans = root[start + k]\n print(ans)\nelse:\n for i in range(k):\n now = a[now - 1]\n print(now)']
|
['Runtime Error', 'Accepted']
|
['s115143592', 's339515554']
|
[32236.0, 32380.0]
|
[153.0, 153.0]
|
[659, 606]
|
p02684
|
u170839742
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\ngraph = [set() for i in range(N)]\nfor i, a in enumerate(A):\n graph[i].add(a - 1)\n\nstack = [0]\nseen = {0}\npath = []\ndist = [-1] * N\nwhile stack:\n cur = stack.pop()\n if dist[cur] != -1:\n break\n dist[cur] = len(path)\n path.append(cur)\n for nei in graph[cur]:\n if nei not in seen:\n stack.append(nei)\n seen.add(nei)\n\nnot_loop = graph[cur].pop()\nloop = len(path) - not_loop\nif K < not_loop:\n print(path[K] + 1)\nelse:\n K -= not_loop\n K %= loop\n print(path[not_loop + K - 1] + 1)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\ngraph = [set() for i in range(N)]\nfor i, a in enumerate(A):\n graph[i].add(a - 1)\n\nstack = [0]\nseen = {0}\npath = []\ndist = [-1] * N\nwhile stack:\n cur = stack.pop()\n if dist[cur] != -1:\n break\n dist[cur] = len(path)\n path.append(cur)\n for nei in graph[cur]:\n if nei not in seen:\n stack.append(nei)\n seen.add(nei)\n\nnot_loop = dist[graph[cur].pop()]\nloop = len(path) - not_loop\nif K < not_loop:\n print(path[K] + 1)\nelse:\n K -= not_loop\n K %= loop\n print(path[not_loop + K] + 1)']
|
['Runtime Error', 'Accepted']
|
['s402388748', 's378981158']
|
[90848.0, 90788.0]
|
[527.0, 538.0]
|
[606, 608]
|
p02684
|
u173720816
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nnode = [0] * (N + 1)\nindex = 1\nloop_flag = False\n\nfor i in range(1, N + 1):\n tmp = A[index - 1]\n if not node[tmp]:\n index = tmp\n node[index] += i\n else:\n pre = node[tmp]\n loop = index - node[tmp]\n if loop > 1:\n answer = node.index((K - pre) % loop + pre)\n else:\n answer = tmp\n loop_flag = True\n print(answer)\n break\n\nif loop_flag:\n print(index)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nindex = 0\ncount = 0\nnode = [1]\nwhile True:\n next = A[index]\n node.append(next)\n if A[next - 1] in node:\n catch_point = A[next - 1]\n break\n index = next - 1\n\nfor point in node:\n if point == catch_point:\n break\n else:\n count += 1\n\nprint(catch_point, count)\nidx = (K - count) % (len(node) - count)\n\nprint(node[count + idx])', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nnode = [0] * (N + 1)\nindex = 1\nloop_flag = False\n\nfor i in range(1, K + 1):\n tmp = A[index - 1]\n if not node[tmp]:\n index = tmp\n node[index] += i\n else:\n pre = node[tmp]\n loop = index - node[tmp]\n if loop > 1:\n answer = node.index((K - pre) % loop + pre)\n else:\n answer = tmp\n loop_flag = True\n print(answer)\n break\n\nif loop_flag:\n print(index)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nnode = [0] * (N + 1)\nindex = 1\nloop_flag = False\n\nfor i in range(1, K + 1):\n tmp = A[index - 1]\n if not node[tmp]:\n index = tmp\n node[index] += i\n else:\n pre = node[tmp]\n loop = index - node[tmp]\n if loop > 1:\n answer = node.index((K - pre) % loop + pre)\n else:\n answer = tmp\n loop_flag = True\n print(answer)\n break\n\nif loop_flag == False:\n print(index)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nindex = 1\nroute = [index]\nnode = {index}\n\nfor i in range(1, K + 1):\n index = A[index - 1]\n if index in node:\n pre = route.index(index)\n loop = len(route)\n route_idx = (K - pre) % (loop - pre) + pre\n print(route[route_idx])\n break\n else:\n route.append(index)\n node.add(index)\nelse:\n print(index)']
|
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s183808140', 's326812736', 's488711038', 's533472351', 's800882678']
|
[32380.0, 32300.0, 32380.0, 32388.0, 32188.0]
|
[144.0, 2207.0, 135.0, 148.0, 176.0]
|
[511, 437, 511, 520, 425]
|
p02684
|
u183383816
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import math,sys\nfrom sys import stdin, stdout\nfrom collections import Counter, defaultdict, deque\ninput = stdin.readline\nI = lambda:int(input())\nli = lambda:list(map(int,input().split()))\n\ndef case():\n n,k=li()\n a=li()\n d=defaultdict(int)\n i=0\n d[1]=1\n c=0\n ans=[1]\n while(a[i] not in d):\n d[a[i]]=1\n c+=1 \n ans.append(a[i])\n i=a[i]-1\n print(ans)\n # print(i)\n if(k<len(a)):\n print(ans[k%len(ans)])\n return\n for j in range(len(ans)):\n if(ans[j]==a[i]):\n ans=ans[j:]\n k-=j\n break \n\n #print(ans,k)\n print(ans[(k)%len(ans)])\n \n\n\n\n\nfor _ in range(1):\n case()', 'import math,sys\nfrom sys import stdin, stdout\nfrom collections import Counter, defaultdict, deque\ninput = stdin.readline\nI = lambda:int(input())\nli = lambda:list(map(int,input().split()))\n\ndef case():\n n,k=li()\n a=li()\n d=defaultdict(int)\n i=0\n d[1]=1\n c=0\n ans=[1]\n while(a[i] not in d):\n d[a[i]]=1\n c+=1 \n ans.append(a[i])\n i=a[i]-1\n # print(i)\n #print(ans)\n if(k<len(ans)):\n print(ans[k%len(ans)])\n return\n for j in range(len(ans)):\n if(ans[j]==a[i]):\n ans=ans[j:]\n k-=j\n break \n\n #print(ans,k)\n print(ans[(k)%len(ans)])\n \n\n\n\n\nfor _ in range(1):\n case()']
|
['Wrong Answer', 'Accepted']
|
['s832143223', 's105283493']
|
[37144.0, 37204.0]
|
[178.0, 163.0]
|
[682, 685]
|
p02684
|
u184817817
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['#D\nn,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nnxt = 1\nloop = []\ntset = set()\nfinal = -1\nwhile 1:\n loop.append(nxt)\n tset.add(nxt)\n nxt = a[nxt-1]\n if nxt in tset:\n final = nxt \n break\nm = -1\nfor i in range(len(loop)):\n if loop[i]==final:\n m = i\n break\nl = len(loop)\nif k < m:\n print(loop[k])\nelse:\n print(loop[(k-m)%(l-m)+m],k,m)\n# print(loop[(k+1)%l])\nprint(loop)', '#D\nn,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nnxt = 1\nloop = []\ntset = set()\nfinal = -1\nwhile 1:\n loop.append(nxt)\n tset.add(nxt)\n nxt = a[nxt-1]\n if nxt in tset:\n final = nxt \n break\nm = -1\nfor i in range(len(loop)):\n if loop[i]==final:\n m = i\n break\nl = len(loop)\nif k < m:\n print(loop[k])\nelse:\n print(loop[(k-m)%(l-m)+m])\n# print(loop[(k+1)%l])']
|
['Wrong Answer', 'Accepted']
|
['s897826603', 's945875315']
|
[32112.0, 32380.0]
|
[180.0, 167.0]
|
[458, 442]
|
p02684
|
u185948224
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nvisited = [-1] * N\nvisited[0] = 0\nnxt = 1\ncnt = 1\nfor i in range(N):\n nxt = A[nxt-1]\n if visited[nxt-1] == -1:\n visited[nxt-1] = cnt\n cnt += 1\n else:\n cycl = i + 1 - visited[nxt-1]\n m = visited[nxt-1]\n break\nprint(visited, cycl)\n\nk = (K - m) % cycl + m\n\nfor i in range(N):\n if visited[i] == k:\n print(i+1)\n break\n', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nvisited = [-1] * N\nvisited[0] = 0\nnxt = 1\ncycl = N\nm = 0\nfor i in range(N):\n nxt = A[nxt-1]\n if visited[nxt-1] == -1:\n visited[nxt-1] = i+1\n else:\n cycl = i + 1 - visited[nxt-1]\n m = visited[nxt-1]\n break\nif K < m: k = K\nelse:\n k = (K - m) % cycl + m\n\nfor i in range(N):\n if visited[i] == k:\n print(i+1)\n break\n']
|
['Wrong Answer', 'Accepted']
|
['s657940895', 's375426197']
|
[32380.0, 32376.0]
|
[216.0, 162.0]
|
[444, 438]
|
p02684
|
u187235390
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["import sys\nfrom collections import deque\nimport copy\ndef main():\n N, K = map(int, input().split())\n A = [(int(i) - 1) for i in input().split()]\n d = []\n for i in range(N):\n d.append(-1)\n d[0] = 0\n now = 0\n cycle = 0\n ans = -1\n a = 0\n flag = True\n while a < K:\n if flag:\n if d[A[now]] == -1:\n d[A[now]] = d[now] + 1\n else:\n cycle = (d[now] + 1) - d[A[now]]\n K = (K - (d[now] + 1)) % cycle\n a = 0\n flag = False\n a += 1\n now = A[now]\n print(now + 1)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nfrom collections import deque\nimport copy\ndef main():\n N, K = map(int, input().split())\n A = [(int(i) - 1) for i in input().split()]\n d = []\n for i in range(N):\n d.append(-1)\n d[0] = 0\n now = 0\n cycle = 0\n ans = -1\n a = 0\n flag = True\n while K > 0:\n if flag:\n if d[A[now]] == -1:\n d[A[now]] = d[now] + 1\n else:\n cycle = (d[now] + 1) - d[A[now]]\n K %= cycle\n flag = False\n if K == 0:\n break\n K -= 1\n now = A[now]\n print(now + 1)\n\n\nif __name__ == '__main__':\n main()\n"]
|
['Wrong Answer', 'Accepted']
|
['s563605143', 's942455033']
|
[33720.0, 33736.0]
|
[144.0, 151.0]
|
[648, 659]
|
p02684
|
u191680842
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['\nn, k = map(int, input().split())\nA = map(int,input().split())\nflag = [True]*n\np = 0\nrt = [1]\n\nwhile flag[p]:\n flag[p] = False\n p = A[p] -1\n rt.append(p+1)\n\nto_p = rt.index(rt[-1])\np2p = rt[to_p:-1]\np2p_len = len(p2p)\n\nif k < p2p_len:\n print(rt[k])\nelse:\n print(p2p[(k-to_p)%p2p_len])', 'n, k = map(int, input().split())\nA = list(map(int,input().split()))\nflag = [True]*n\nroot = [1]\nnow = 0\n\nwhile flag[now]:\n flag[now] = False\n now = A[now] -1\n root.append(now+1)\n\nto_p = root.index(root[-1])\np2p = root[to_p:-1]\nrooplen = len(p2p)\n\nif k < rooplen:\n print(root[k])\nelse: \n idx = (k-to_p)\n idx %= p2p_len\n print(p2p[idx])', 'n, k = map(int,input().split())\na = list(map(int,input().split()))\n\ns = [True] * n \nc = [1] \nnow = 0 \nwhile s[now]:\n s[now] = False \n now = a[now] - 1\n c.append(now+1)\n\nstart_cycle = c.index(c[-1]) \nloop = c[start_cycle:-1] \ncycle = len(loop)\n\nif k < start_cycle: \n print(c[k])\nelse:\n k -= start_cycle\n k %= cycle\n print(loop[k])']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s319209846', 's599199517', 's651692228']
|
[24568.0, 32308.0, 32200.0]
|
[46.0, 151.0, 147.0]
|
[299, 357, 356]
|
p02684
|
u192042624
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import numpy as np\nimport sys\nimport math\nfrom collections import defaultdict\n\nN , K = map(int,input().split())\nA = list(map(int,input().split()))\n\nha = defaultdict(int)\nans = defaultdict(int)\ns = set()\ns.add(1)\nss = set()\nmod = 0\nmod2 = 0\nnext = 0\nind = 0\nflag = 0\nwhile True:\n if A[next] in s and flag == 0:\n flag = 1\n ha[0] = A[next]\n ans[0] = A[next]\n ss.add(A[next])\n ind = 0\n mod += 1\n continue\n # next = A[next] - 1 \n elif flag == 1:\n ans[ind+1] = A[next]\n ss.add(A[next])\n next = A[next] - 1\n if A[next] in ss :\n mod2 += 1\n break\n mod2 += 1\n ind += 1\n continue\n\n ha[ind+1] = A[next]\n s.add(A[next])\n next = A[next] - 1\n mod += 1\n ind += 1\n\nif mod > K :\n print(ha[K % mod])\nelse:\n if K - mod <0 :\n print(ha[K])\n else:\n print(ans[(K-mod)%mod2])\n', 'import numpy as np\nimport sys\nimport math\nfrom collections import defaultdict\n\nN , K = map(int,input().split())\nA = list(map(int,input().split()))\n\nha = defaultdict(int)\nans = defaultdict(int)\ns = set()\ns.add(1)\nss = set()\nmod = 0\nmod2 = 0\nnext = 0\nind = 0\nflag = 0\nwhile True:\n if A[next] in s and flag == 0:\n flag = 1\n ha[0] = A[next]\n ans[0] = A[next]\n ss.add(A[next])\n ind = 0\n mod += 1\n continue\n # next = A[next] - 1 \n elif flag == 1:\n next = A[next] - 1\n ans[ind+1] = A[next]\n mod2 += 1\n if A[next] in ss :\n break\n ss.add(A[next])\n ind += 1\n continue\n\n ha[ind+1] = A[next]\n s.add(A[next])\n next = A[next] - 1\n mod += 1\n ind += 1\n\nif mod >= K :\n print(ha[K % mod])\nelse:\n print(ans[(K-mod)%mod2])\n\n#print(ha)\n#print(ans)']
|
['Wrong Answer', 'Accepted']
|
['s017892521', 's258493366']
|
[89860.0, 90008.0]
|
[455.0, 491.0]
|
[923, 870]
|
p02684
|
u197968862
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int,input().split())\na = list(map(int,input().split()))\n\ncitys = [False] * n\nnow = 0\ncitys[0] = True\ncostt = 0\nwhile True:\n now = a[now] - 1\n if citys[now]:\n costt += 1\n break\n else:\n citys[now] = True\n costt += 1\n\ncitys = [False] * n\ncitys[now] = True\ncheck = [0] * n\ncheck[now] = 1\ncost = 0\nwhile True:\n now = a[now] - 1\n if citys[now]:\n cost += 1\n break\n else:\n citys[now] = True\n cost += 1\n check[now] = cost + 1\n\ncostt -= cost\nd = ((k - costt) % cost + 1) % cost\nif costt > k:\n i = 0\n while i != k:\n now = a[now] - 1\n i += 1\n print(now+1)\n quit()\nans = check.index(d)\nprint(ans+1)', 'n, k = map(int,input().split())\na = list(map(int,input().split()))\n\ncitys = [False] * n\nnow = 0\ncitys[0] = True\ncostt = 0\nwhile True:\n now = a[now] - 1\n if citys[now]:\n costt += 1\n break\n else:\n citys[now] = True\n costt += 1\n\ncitys = [False] * n\ncitys[now] = True\ncheck = [0] * n\ncheck[now] = 1\ncost = 0\nwhile True:\n now = a[now] - 1\n if citys[now]:\n cost += 1\n break\n else:\n citys[now] = True\n cost += 1\n check[now] = cost + 1\n\ncostt -= cost\nd = (k - costt) % cost + 1\nif costt > k:\n i = 0\n while i != k:\n now = a[now] - 1\n i += 1\n print(now+1)\n quit()\nans = check.index(d)\nprint(ans+1)\nprint(check)', 'n, k = map(int,input().split())\na = list(map(int,input().split()))\n\ns = [-1] * n\nc = [1]\nt = 0\nnow = 0\nwhile s[now] == -1:\n s[now] = t\n now = a[now] - 1\n c.append(now+1)\n t += 1\n\nstart_cycle = c.index(c[-1])\nloop = c[start_cycle:-1]\ncycle = len(loop)\n\nif k < start_cycle:\n print(c[k])\nelse:\n k -= start_cycle\n k %= cycle\n print(loop[k])']
|
['Wrong Answer', 'Wrong Answer', 'Accepted']
|
['s051920173', 's154333440', 's422020059']
|
[32336.0, 32408.0, 32876.0]
|
[209.0, 225.0, 176.0]
|
[703, 707, 360]
|
p02684
|
u198668088
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['def search_loop(list_route, now):\n list_route.append(list_a[now-1])\n for start in range(len(list_route)):\n for end in range(start+1, len(list_route)):\n if list_route[start] == list_route[end]:\n return start, end - start\n return search_loop(list_route, list_a[now-1])\n\n\nN, K = map(int, input().split())\nlist_a = list(map(int, input().split()))\nif list_a[0] == 1:\n print(1)\n quit()\nlist_route = [1]\nloop_start, loop_length = search_loop(list_route, 1)\nt = (K-loop_start+1) % (loop_length+1)\nprint(list_route[t])\nprint(list_a)', 'N, K = map(int, input().split())\nA = list(i - 1 for i in map(int, input().split()))\nnow = 0\nloop_start = 0\nload_list = [-1] * N\nY = - 1\nwhile loop_start < K:\n if load_list[now] == -1:\n load_list[now] = loop_start\n now = A[now]\n loop_start += 1\n else:\n start = load_list[now]\n end = loop_start - load_list[now]\n Y = start + (K - loop_start) % end\n break\n\nif Y == -1:\n print(now + 1)\nelse:\n print(load_list.index(Y) + 1)']
|
['Wrong Answer', 'Accepted']
|
['s126576608', 's273892141']
|
[32284.0, 32344.0]
|
[2206.0, 141.0]
|
[571, 479]
|
p02684
|
u204842730
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k=map(int,input().split())\na=list(map(int,input().split()))\nvisit=[1]\npos=0\nwhile True:\n visit.append(a[pos])\n if a[pos]-1 in visit:\n break\n pos=a[pos]-1\nloop=[]\nlooppos=visit[-1]-1\nwhile True:\n loop.append(a[looppos])\n looppos=a[looppos]-1\n if a[looppos] in loop:\n break\nprint(visit)\nprint(loop)\nif len(visit)>k:\n print(visit[k])\nelse:\n t=(k%len(visit))\n print(loop[t])', 'n, k = map(int, input().split())\na = list(map(lambda x: int(x)-1, input().split()))\n\nnum = 0\nli = [0]\nflag = [True] * n\nflag[0] = False\n\nfor i in range(k):\n num = a[num]\n if flag[num]:\n li.append(num)\n flag[num] = False\n else:\n break\n\nd = li.index(num)\nans = (k-d)%(len(li)-d)+d\nprint(li[ans]+1)']
|
['Runtime Error', 'Accepted']
|
['s765736268', 's506847337']
|
[32296.0, 32380.0]
|
[2206.0, 142.0]
|
[413, 325]
|
p02684
|
u212328220
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nal = list(map(int, input().split()))\n\nvisited_towns = []\nfor i in range(N):\n next_town = al[visited_towns[i] - 1]\n if next_town in visited_towns:\n loop_sta = visited_towns.index((next_town)) \n loop_end = len(visited_towns) \n loop_length = loop_end - loop_sta \n amari = (K - loop_sta) % loop_length\n ans = visited_towns[loop_sta + amari]\n print(ans)\n exit()\n else:\n visited_towns.append(next_town)\n\nprint(visited_towns[-1])\n\n', 'N, K = map(int, input().split())\nal = list(map(int, input().split()))\n\nroute = [1]\nfor i in range(N):\n next_town = al[route[i]-1]\n if route.count(next_town) > 1:\n loop_start = route.index(next_town)\n loop_end = len(route)\n loop_length = loop_end - loop_start\n amari = (K - loop_start)%loop_length\n ans = route[loop_start + amari]\n #print(route)\n print(ans)\n exit()\n else:\n route.append(next_town)\n\nans = route[-1]\nprint(ans)\n', 'N, K = map(int, input().split())\nal = list(map(int, input().split()))\n\nvisited= [1]\ned = set([1])\nfor i in range(K):\n next_town = al[visited[i] - 1]\n if next_town in ed:\n loop_sta = visited.index((next_town)) \n loop_end = len(visited) \n loop_length = loop_end - loop_sta \n amari = (K - loop_sta) % loop_length\n ans = visited[loop_sta + amari]\n print(ans)\n exit()\n else:\n visited.append(next_town)\n ed.add(next_town)\n continue\n\nelse:\n print(visited[-1])\n\n']
|
['Runtime Error', 'Wrong Answer', 'Accepted']
|
['s673693873', 's952562369', 's902978882']
|
[32384.0, 32216.0, 32376.0]
|
[68.0, 2206.0, 150.0]
|
[687, 497, 701]
|
p02684
|
u212786022
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ncnt = [0]*N\ntown = 1\nfor i in range(K):\n if cnt[town-1] ==1:\n break\n\n cnt[town-1] += 1\n town = A[town-1]\n\n\nans1 = sum(cnt)\n\nimport copy\ntown2 = copy.deepcopy(town)\n\ncnt2 = [0]*N\n\nfor i in range(K):\n if cnt2[town2-1] ==1:\n break\n\n cnt2[town2-1] += 1\n town2 = A[town2-1]\n \nans2 = sum(cnt2)\n\nif K <= (ans1-ans2):\n print(town)\nelse:\n town3 = 1\n cnt3=[0]*N\n K2 = ((K-(ans1-ans2))%(ans2))+(ans1-ans2)\n print(K2)\n for i in range(K2):\n if cnt3[town3-1] ==1:\n break\n\n cnt[town3-1] += 1\n town3 = A[town3-1]\n print(town3)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ncnt = [0]*N\ntown = 1\nfor i in range(K):\n if cnt[town-1] ==1:\n break\n\n cnt[town-1] += 1\n town = A[town-1]\n\n\nans1 = sum(cnt)\n\nimport copy\ntown2 = copy.deepcopy(town)\n\ncnt2 = [0]*N\n\nfor i in range(K):\n if cnt2[town2-1] ==1:\n break\n\n cnt2[town2-1] += 1\n town2 = A[town2-1]\n \nans2 = sum(cnt2)\n\nif K <= 10**8:\n town4 = 1\n for i in range(K):\n town4 = A[town4-1]\n print(town4)\nelse:\n town3 = 1\n cnt3=[0]*N\n K2 = ((K-(ans1-ans2))%(ans2))+(ans1-ans2)\n for i in range(K2):\n if cnt3[town3-1] ==1:\n break\n\n cnt[town3-1] += 1\n town3 = A[town3-1]\n print(town3)']
|
['Wrong Answer', 'Accepted']
|
['s060602640', 's504133985']
|
[32388.0, 32008.0]
|
[214.0, 228.0]
|
[668, 713]
|
p02684
|
u213497190
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int, input().split())\nA = list(map(int, input().split()))\nA = {i+1:A[i] for i in range(len(A))}\n\nif k <= n:\n current = 1\n for i in range(k):\n current = A[current]\n print(current)\nelse:\n current = 1\n pos = []\n visited = {i+1:0 for i in range(len(A))}\n for i in range(n):\n pos.append(current)\n visited[current] += 1\n if visited[current] == 2:\n circle_len = len(pos)\n print(pos[k%circle_len])\n break\n current = A[current]', 'n,k = map(int, input().split())\nA = list(map(int, input().split()))\nA = {i+1:A[i] for i in range(len(A))}\n\nif k <= n:\n current = 1\n for i in range(k):\n current = A[current]\n print(current)\nelse:\n current = 1\n count = 0\n pos = []\n visited = {i+1:-1 for i in range(len(A))}\n for i in range(k):\n \n if visited[current] >= 0:\n circle = pos[visited[current]:]\n ans = k - visited[current]\n ans = ans % len(circle)\n #print(visited[current], ans, circle, circle[ans])\n print(circle[ans])\n\n\n# print(pos[k%circle_len])\n break\n \n pos.append(current)\n visited[current] = count\n count += 1\n current = A[current]']
|
['Wrong Answer', 'Accepted']
|
['s888816162', 's793897600']
|
[58492.0, 63392.0]
|
[281.0, 261.0]
|
[517, 881]
|
p02684
|
u216015528
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["#!/usr/bin/env python3\ndef main():\n N, K = map(int, input().split())\n A = [int(x) - 1 for x in input().split()]\n\n way = []\n now = 0\n for _ in range(K):\n if now in way:\n loop_start = way.index(now)\n loop = way[loop_start:]\n K -= len(way[:loop_start])\n now = loop[K - len(way[:loop_start]) % len(loop)]\n break\n way.append(now)\n now = A[now]\n print(now + 1)\n\n\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\ndef main():\n N, K = map(int, input().split())\n A = [int(x) - 1 for x in input().split()]\n\n way = []\n seen = [False for _ in [0] * (2 * 10 ** 5 + 1)]\n now = 0\n for _ in range(K):\n if seen[now]:\n loop_start = way.index(now)\n loop = way[loop_start:]\n K -= len(way[:loop_start])\n now = loop[K % len(loop)]\n break\n way.append(now)\n seen[now] = True\n now = A[now]\n print(now + 1)\n\n\nif __name__ == '__main__':\n main()\n"]
|
['Runtime Error', 'Accepted']
|
['s719719342', 's228062717']
|
[32332.0, 32240.0]
|
[2206.0, 129.0]
|
[489, 541]
|
p02684
|
u217627525
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['def main():\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n cnt=0\n b=[1]\n res=[-1]*n\n res[0]=0\n flg=0\n now=1\n start=0\n t=1\n while flg==0:\n cnt+=1\n if res[a[now-1]-1]==-1:\n res[a[now-1]-1]=cnt\n b.append(a[now-1])\n now=a[now-1]\n print(now)\n else:\n start=res[a[now-1]-1]\n t=cnt-start\n if cnt<=k:\n flg=1\n k-=start\n else:\n flg=2\n print(cnt,a[now-1],res,flg)\n print(start,t)\n print(b)\n if flg==1:\n print(b[start+(k%t)])\n else:\n print(b[k])\nif __name__=="__main__":\n main()', 'def main():\n n,k=map(int,input().split())\n a=list(map(int,input().split()))\n cnt=0\n b=[1]\n res=[-1]*n\n res[0]=0\n flg=0\n now=1\n start=0\n t=1\n while flg==0:\n cnt+=1\n if res[a[now-1]-1]==-1:\n res[a[now-1]-1]=cnt\n b.append(a[now-1])\n now=a[now-1]\n else:\n start=res[a[now-1]-1]\n t=cnt-start\n if cnt<=k:\n flg=1\n k-=start\n else:\n flg=2\n if flg==1:\n print(b[start+(k%t)])\n else:\n print(b[k])\nif __name__=="__main__":\n main()']
|
['Wrong Answer', 'Accepted']
|
['s097215570', 's286269041']
|
[32408.0, 32380.0]
|
[292.0, 161.0]
|
[710, 615]
|
p02684
|
u219494936
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split(" "))\ntowns = list(map(lambda x: int(x)-1, input().split(" ")))\nassert len(towns) == N\n\nprint(towns)\n\nscore = {0: 0}\ncurrent = 0\nmove = 0\nwhile 1:\n next_town = towns[current]\n move += 1\n # print(f"move {current} to {next_town}")\n if score.get(next_town) is not None:\n # print(f"find loop!")\n loop_move = move - score.get(next_town)\n loop_town = next_town\n until_loop = score.get(next_town)\n # print(f"loop start town : ", loop_town)\n # print(f"cost to start to loop town : ", until_loop)\n # print(f"loop length : ", loop_move)\n break\n score[next_town] = move\n current = next_town\n\nif K < until_loop:\n result = 0\n for k in range(K):\n result = towns[result]\nelse:\n result = loop_town\n for k in range((K - until_loop) % loop_move):\n result = towns[result]\nprint(result + 1)\n\n', 'visited = []\ncurrent = 0\nwhile 1:\n if K == 0:\n break\n current = towns[current]\n K -= 1\n if current in visited:\n L = 0\n tcurrent = current\n while 1:\n tcurrent = towns[tcurrent]\n L += 1\n if tcurrent == current:\n break\n break\n visited.append(current)\n\nK = K % L\nfor _ in range(K):\n current = towns[current]\nprint(current + 1)', 'N, K = map(int, input().split(" "))\ntowns = list(map(lambda x: int(x)-1, input().split(" ")))\nassert len(towns) == N\n\n# print(towns)\n\n# score = {0: 0}\n# current = 0\n# move = 0\n# while 1:\n# next_town = towns[current]\n# move += 1\n# # print(f"move {current} to {next_town}")\n# if score.get(next_town) is not None:\n# # print(f"find loop!")\n# loop_move = move - score.get(next_town)\n# loop_town = next_town\n# until_loop = score.get(next_town)\n# # print(f"loop start town : ", loop_town)\n# # print(f"cost to start to loop town : ", until_loop)\n# # print(f"loop length : ", loop_move)\n# break\n# score[next_town] = move\n# current = next_town\n\n\n# result = 0\n# for k in range(K):\n# result = towns[result]\n# else:\n# result = loop_town\n# for k in range((K - until_loop) % loop_move):\n# result = towns[result]\n# print(result + 1)\n\nvisited = set([])\ncurrent = 0\nwhile 1:\n if K == 0:\n break\n current = towns[current]\n K -= 1\n if current in visited:\n L = 0\n tcurrent = current\n while 1:\n tcurrent = towns[tcurrent]\n L += 1\n if tcurrent == current:\n break\n break\n visited.add(current)\n\nK = K % L\nprint(K)\nfor _ in range(K):\n current = towns[current]\nprint(current + 1)\n', 'N, K = map(int, input().split(" "))\ntowns = list(map(lambda x: int(x)-1, input().split(" ")))\nassert len(towns) == N\n\n# print(towns)\n\n# score = {0: 0}\n# current = 0\n# move = 0\n# while 1:\n# next_town = towns[current]\n# move += 1\n# # print(f"move {current} to {next_town}")\n# if score.get(next_town) is not None:\n# # print(f"find loop!")\n# loop_move = move - score.get(next_town)\n# loop_town = next_town\n# until_loop = score.get(next_town)\n# # print(f"loop start town : ", loop_town)\n# # print(f"cost to start to loop town : ", until_loop)\n# # print(f"loop length : ", loop_move)\n# break\n# score[next_town] = move\n# current = next_town\n\n\n# result = 0\n# for k in range(K):\n# result = towns[result]\n# else:\n# result = loop_town\n# for k in range((K - until_loop) % loop_move):\n# result = towns[result]\n# print(result + 1)\n\nL = None\nvisited = set([])\ncurrent = 0\nwhile 1:\n if K == 0:\n break\n current = towns[current]\n K -= 1\n if current in visited:\n L = 0\n tcurrent = current\n while 1:\n tcurrent = towns[tcurrent]\n L += 1\n if tcurrent == current:\n break\n break\n visited.add(current)\n\nif L is not None:\n K = K % L\n \n for _ in range(K):\n current = towns[current]\nprint(current + 1)\n']
|
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s190230286', 's722468310', 's770208586', 's587551943']
|
[40352.0, 9028.0, 32412.0, 32288.0]
|
[242.0, 24.0, 159.0, 186.0]
|
[842, 365, 1275, 1312]
|
p02684
|
u221301671
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\na = tuple(map(int, input().split()))\n\ni = 0\naa = 0\nvisited = {}\nfor i in range(k):\n aa = a[aa] - 1\n if aa in visited:\n s, e = visited[aa], i\n loop = e - s\n k = s + ((k - s) % loop)\n exit(0)\n visited[aa] = i\n\nprint(aa + 1)\n', 'n, k = map(int, input().split())\na = tuple(map(int, input().split()))\n\ni = 0\naa = 0\nvisited = {}\nfor i in range(k):\n aa = a[aa] - 1\n if aa in visited:\n s, e = visited[aa], i\n loop = e - s\n k = s + (((k-1) - s) % loop)\n print(list(visited.keys())[k] + 1)\n exit(0)\n visited[aa] = i\n\nprint(aa+1)\n']
|
['Wrong Answer', 'Accepted']
|
['s641035618', 's127526708']
|
[33144.0, 33104.0]
|
[137.0, 119.0]
|
[292, 337]
|
p02684
|
u224762261
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\nA = [0] + list(map(int, input().split()))\nnow = 1\nused = [-228] * (n + 191)\nused[1] = -1\ncn = -292\nfor _ in range(k):\n now = A[now]\n if used[now] != -228:\n cn = _ + 1 - used[now]\n break\n used[now] = _\nif cn == -292:\n print(now)\n exit(0)\nfor i in range(k % cn):\n now = A[now]\nprint(now)\n', 'n, k = map(int, input().split())\nA = [0] + list(map(int, input().split()))\nnow = 1\nused = [-228] * (n + 191)\nused[1] = -1\ncn = -292\nahah = 1\nfor _ in range(k):\n now = A[now]\n if used[now] != -228:\n cn = _ + 1 - used[now] - 1\n break\n used[now] = _\n ahah += 1\nif cn == -292:\n print(now)\n exit(0)\nfor i in range((k - ahah) % cn):\n now = A[now]\nprint(now)\n']
|
['Wrong Answer', 'Accepted']
|
['s253730273', 's153315937']
|
[32376.0, 32376.0]
|
[147.0, 132.0]
|
[351, 387]
|
p02684
|
u228759454
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\na = list(map(int, input().split()))\n\nd = {}\nd_n = {}\nfirst_d_n = {}\nfor i in range(N):\n d[i+1] = a[i]\n if i+1 == 1:\n d_n[i+1] = 1\n else:\n d_n[i+1] = 0\n\nm = 1\nk = 0 \nfirst_d_n[1] = 0\n\n\nwhile m:\n m = d[m]\n d_n[m] += 1\n k += 1\n if d_n[m] == 1:\n first_d_n[m] = k\n \n if d_n[m] == 2:\n break\n \nfirst_n = first_d_n[m]\n\nloop_mod = (K - first_n) % (k - first_n)\n#print(loop_mod)\n\nif loop_mod == 0:\n print(m)\nfor l in range(loop_mod):\n m = d[m]\n print(m)\n\n# print(first_d_n[loop_mod - ', 'N, K = map(int, input().split())\na = list(map(int, input().split()))\n\nd = {}\nd_n = {}\nfirst_d_n = {}\nfor i in range(N):\n d[i+1] = a[i]\n if i+1 == 1:\n d_n[i+1] = 1\n else:\n d_n[i+1] = 0\n\nm = 1\nk = 0 \nfirst_d_n[1] = 0\n\nwhile m:\n m = d[m]\n d_n[m] += 1\n k += 1\n if d_n[m] == 1:\n first_d_n[m] = k\n \n if d_n[m] == 2:\n break\n \nfirst_n = first_d_n[m] \n\nif K - first_n >= 0:\n loop_mod = (K - first_n) % (k - first_n)\n #print(loop_mod)\n\n if loop_mod == 0:\n print(m)\n else: \n for l in range(loop_mod):\n m = d[m]\n print(m)\n\n # print(first_d_n[loop_mod - \nelse:\n m = 1\n for l in range(K):\n m = d[m]\n print(m) \n \n ']
|
['Wrong Answer', 'Accepted']
|
['s841913779', 's134485890']
|
[76428.0, 76540.0]
|
[504.0, 451.0]
|
[554, 709]
|
p02684
|
u235783479
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\nA = [-1] + A\n\nvisit = {}\nn = 1\ncnt = 0\nremain = K\n# print("remain:", remain)\nwhile(n not in visit.keys()):\n visit[n] = cnt\n cnt+=1\n n = A[n]\n remain -= 1\n if (remain==0):\n print(n)\n exit()\n# remain -=1\n\nprint(n, visit[n], cnt)\nd = cnt - visit[n]\nprint(d)\nprint("d: ", d)\nprint("remain:", remain)\nremain = remain%d\nprint("remain:", remain)\nprint("current: ", n)\nwhile(remain > 0):\n remain -= 1\n n = A[n]\n # print("new n:", n)\nprint(n)\n\n', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\nA = [-1] + A\n\nvisit = {}\nn = 1\ncnt = 0\nremain = K\n# print("remain:", remain)\nwhile(n not in visit.keys()):\n visit[n] = cnt\n cnt+=1\n n = A[n]\n remain -= 1\n if (remain==0):\n print(n)\n exit()\n# remain -=1\n\n# print(n, visit[n], cnt)\nd = cnt - visit[n]\n# print(d)\n# print("d: ", d)\n# print("remain:", remain)\nremain = remain%d\n# print("remain:", remain)\n# print("current: ", n)\nwhile(remain > 0):\n remain -= 1\n n = A[n]\n # print("new n:", n)\nprint(n)\n\n']
|
['Wrong Answer', 'Accepted']
|
['s497477207', 's039291018']
|
[32412.0, 32300.0]
|
[139.0, 149.0]
|
[542, 554]
|
p02684
|
u240630407
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['# import itertools\n# import math\nimport sys\n\n# import numpy as np\n\n# N = int(input())\n# S = input()\n# n, *a = map(int, open(0))\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\nA.insert(0, 0)\ncnt = [0] * (N + 1)\n\nj = 1\ntimes_s = 0\ntimes_e = 0\ncycle = 0\nfor i in range(N + 1):\n if i == K:\n print(j)\n sys.exit()\n cnt[j] += 1\n if cnt[j] == 2:\n times_e = i\n cycle = j\n break\n j = A[j]\n\nj = 1\nfor i in range(N + 1):\n if j == cycle:\n times_s = i\n break\n j = A[j]\n\nprint(A, cnt)\n\nprint(times_s, times_e, cycle)\n\nK_eff = (K - times_s) % (times_e - times_s)\n\nfor i in range(N + 1):\n if i == K_eff:\n print(j)\n sys.exit()\n j = A[j]', '# import itertools\n# import math\nimport sys\n\n# import numpy as np\n\n# N = int(input())\n# S = input()\n# n, *a = map(int, open(0))\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n\n# for l in tree[s]:\n\n\n# dfs(tree, l[0])\n# dfs(tree, 1)\n\nA.insert(0, 0)\ncnt = [0] * (N + 1)\n\nj = 1\ntimes_s = 0\ntimes_e = 0\ncycle = 0\nfor i in range(N + 1):\n if i == K:\n print(j)\n sys.exit()\n cnt[j] += 1\n if cnt[j] == 2:\n times_e = i\n cycle = j\n break\n j = A[j]\n\nj = 1\nfor i in range(N + 1):\n if j == cycle:\n times_s = i\n break\n j = A[j]\n\n#print(A, cnt)\n\n#print(times_s, times_e, cycle)\n\nK_eff = (K - times_s) % (times_e - times_s)\n\nfor i in range(N + 1):\n if i == K_eff:\n print(j)\n sys.exit()\n j = A[j]']
|
['Wrong Answer', 'Accepted']
|
['s181066640', 's455895070']
|
[32368.0, 32360.0]
|
[179.0, 146.0]
|
[1357, 1359]
|
p02684
|
u242580186
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i,n) for(int i=0; i<(n); i++)\n#define INF 1001001001\nusing ll = long long;\nusing dd = long double;\n\nconst int D = 60;\nconst int MAX_N = 20005;\nint to[D][MAX_N];\n\n\nint main() {\n int n;\n ll k;\n cin >> n >> k;\n rep(i,n) {\n cin >> to[0][i];\n to[0][i]--;\n }\n\n rep(i,D-1)rep(j,n) {\n to[i+1][j] = to[i][to[i][j]];\n }\n\n int v = 0;\n for (int i = D-1; i >= 0; --i) {\n ll l = 1ll<<i;\n if (l <= k) {\n v = to[i][v];\n k -= l;\n }\n }\n cout << v+1 << endl;\n \n return 0;\n}\n\n', "import sys\nimport time\nst = time.perf_counter()\n# ------------------------------\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\nA = [i-1 for i in A]\n\ncnt = [-1] * N\ncnt[0] = 0\nnow = 0\nfor i in range(1, 1001001001):\n now = A[now]\n if cnt[now] == -1:\n cnt[now] = i\n else:\n circle = i - cnt[now]\n t = cnt[now]\n break\nif K - t > 0:\n amari = (K - t) % circle\n for _ in range(amari):\n now = A[now]\nelse:\n now = 0\n for i in range(K):\n now = A[now]\nprint(now + 1)\n\n# ------------------------------\ned = time.perf_counter()\nprint('time:', ed-st, file=sys.stderr)\n", "import sys\nimport time\nst = time.perf_counter()\ndef inpl():\n return list(map(int, input().split()))\n# ------------------------------\n\nN, K = map(int, input().split())\nA = list(map(lambda a: int(a)-1, input().split()))\nT = [A]\n\nfor i in range(59):\n prev = T[-1]\n T.append([prev[a] for a in prev])\n\nnow = 0\nfor k,v in enumerate(T):\n if ((1<<k)&K)>0:\n now = v[now]\nprint(now+1)\n\n\n# ------------------------------\ned = time.perf_counter()\nprint('time:', ed-st, file=sys.stderr)\n"]
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s372244879', 's443991391', 's718841097']
|
[9008.0, 9052.0, 112180.0]
|
[24.0, 28.0, 1679.0]
|
[617, 636, 493]
|
p02684
|
u243714267
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\n\nli = [0]\nli.extend(list(map(int, input().split())))\ntuita = [0]*(n+1)\ncnt = 0\ntown = 1\n\ndef search(town, times):\n return times + 1\n if times == 0:\n return town\n return search(li[town], times - 1)\n\nwhile True:\n town = li[town]\n cnt += 1\n if tuita[town] == 0:\n tuita[town] = cnt\n else:\n if k < tuita[town]:\n print(search(1, k))\n elif k == tuita[town]:\n print(town)\n else:\n print(search(town, (k - tuita[town]) % (cnt - tuita[town])))\n break\n \n\n \n ', 'n, k = map(int, input().split())\n\nli = [0]\nli.extend(list(map(int, input().split())))\n\ndef search(town, li, times):\n return 1\n if times == 0:\n return town\n return search(li[town], li, times-1)\n\ntuita = [0]*(n+1)\ncnt = 0\ntown = 1\n\nwhile True:\n town = li[town]\n cnt += 1\n if tuita[town] == 0:\n tuita[town] = cnt\n else:\n if k < tuita[town]:\n print(search(1, li, k))\n elif k == tuita[town]:\n print(town)\n else:\n print(search(town, li, (k - tuita[town]) % (cnt - tuita[town])))\n break\n \n\n \n ', 'n, k = map(int, input().split())\n\nli = [0]\nli.extend(list(map(int, input().split())))\n\ndef search(town, times):\n if times == 0:\n return town\n else:\n nextTown = li[town]\n return search(nextTown, times-1)\n\ntuita = [0]*(n+1)\ncnt = 0\ntown = 1\n\nwhile True:\n town = li[town]\n cnt += 1\n if tuita[town] == 0:\n tuita[town] = cnt\n else:\n if k < tuita[town]:\n print(search(1, k))\n elif k == tuita[town]:\n print(town)\n else:\n print("a")\n break\n print(search(town, (k - tuita[town]) % (cnt - tuita[town])))\n break\n ', 'n, k = map(int, input().split())\n\nli = [0]\nli.extend(list(map(int, input().split())))\ntuita = [0]*(n+1)\ncnt = 0\ntown = 1\n\ndef search(town, times):\n return times\n if times <= 0:\n return town\n else:\n return search(li[town], times-1)\n\nwhile True:\n town = li[town]\n cnt += 1\n if tuita[town] == 0:\n tuita[town] = cnt\n else:\n if k < tuita[town]:\n print(search(1, k))\n elif k == tuita[town]:\n print(town)\n else:\n print(search(town, (k - tuita[town]) % (cnt - tuita[town])))\n break\n \n\n \n ', 'n, k = map(int, input().split())\n\nli = [0]\nli.extend(list(map(int, input().split())))\n\ndef search(town, li, times):\n if times == 0:\n return town\n return search(li[town], li, times-1)\n\ntuita = [0]*(n+1)\ncnt = 0\ntown = 1\n\nwhile True:\n town = li[town]\n cnt += 1\n if tuita[town] == 0:\n tuita[town] = cnt\n else:\n if k < tuita[town]:\n break\n print(search(1, li, k))\n elif k == tuita[town]:\n break\n print(town)\n else:\n break\n print(search(town, li, (k - tuita[town]) % (cnt - tuita[town])))\n break\n \n\n \n ', 'n, k = map(int, input().split())\n\nli = [0]\nli.extend(list(map(int, input().split())))\ntuita = [0]*(n+1)\ncnt = 0\ntown = 1\n\nlastTown = 1\nwhile True:\n town = li[town]\n cnt += 1\n if tuita[town] == 0:\n tuita[town] = cnt\n else:\n if k < tuita[town]:\n lastTown = 1\n times = k\n elif k == tuita[town]:\n lastTown = town\n times = 0\n else:\n lastTown = town\n times = (k - tuita[town]) % (cnt - tuita[town])\n break\n\ntown = lastTown\nwhile times > 0:\n if times <= 0:\n break\n times -= 1\n town = li[town]\nprint(town)']
|
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
|
['s224850710', 's253106770', 's389034816', 's518892542', 's721409192', 's457878363']
|
[32272.0, 32384.0, 32328.0, 32376.0, 32380.0, 32240.0]
|
[138.0, 136.0, 143.0, 136.0, 161.0, 187.0]
|
[523, 530, 557, 527, 555, 552]
|
p02684
|
u247830763
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n,k = map(int,input().split())\nls = list(map(int,input().split()))\ni = 1\ndi = [-1]*10\ndi[0] = 0\nwhile True:\n if i == 1:\n a = ls[0]\n di[a-1] = i\n i += 1\n continue\n if i == k+1:\n print(a)\n break\n a = ls[a-1]\n if di[a-1] != -1:\n p = (k+1-di[a-1])%(i-di[a-1])\n s = i-di[a-1]\n if p ==0:\n q = di.index(i-1)+1\n print(q)\n else:\n q = di.index(i-s-1+p)+1\n print(q)\n break\n di[a-1] = i\n i += 1\nprint(di)', 'n,k = map(int,input().split())\nls = list(map(int,input().split()))\nfi = [-1]*(n+1)\nfi[1] = 0\na = 0\naa = 0\nfor i in range(k):\n if fi[ls[a]] == -1:\n fi[ls[a]] = i + 1\n aa = a\n a = ls[a] - 1\n else:\n ind = fi[ls[a]]\n t = (k - ind) % (max(fi) + 1 - ind)\n t += ind\n print(fi.index(t))\n break\nelse:\n print(ls[aa])']
|
['Runtime Error', 'Accepted']
|
['s630370089', 's566922866']
|
[32376.0, 32260.0]
|
[68.0, 145.0]
|
[531, 371]
|
p02684
|
u249218427
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['# -*- coding: utf-8 -*-\n\nN,K = map(int, input().split())\nA = list(map(int, input().split()))\n\nM = K%N\n\ntown_now = 1\n\nfor _ in range(M):\n town_now = A[town_now-1]\n\nprint(town_now)', '# -*- coding: utf-8 -*-\n\nN,K = map(int, input().split())\nA = [0]+list(map(int, input().split()))\n\ntown_list = [-1,0]+[-1 for i in range(N-1)]\ntown_now = 1\nn_teleport = 0\n\nwhile n_teleport<K:\n n_teleport += 1\n town_now = A[town_now]\n if town_list[town_now]==-1:\n town_list[town_now] = n_teleport\n else:\n break\n\nif n_teleport==K:\n print(town_now)\nelse:\n loop_start_town = town_now\n loop_start_time = town_list[town_now]\n loop_len = n_teleport-town_list[town_now]\n M = (K-loop_start_time)%loop_len\n for _ in range(M):\n town_now = A[town_now]\n print(town_now)']
|
['Wrong Answer', 'Accepted']
|
['s706744542', 's584209355']
|
[32380.0, 32244.0]
|
[96.0, 169.0]
|
[179, 575]
|
p02684
|
u250061066
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
["from sys import stdin\ndef main():\n N, K = [int(x) for x in stdin.readline().rstrip().split()]\n A = [int(x)-1 for x in stdin.readline().rstrip().split()]\n X = 0\n C = 0\n Log = []\n while C <= K:\n X = A[X-1]\n C += 1\n if (X in Log) == True:\n break\n Log += [X]\n \n #print(Log)\n #print('C',C)\n #print('X',X)\n \n K = (K - C+1)%(C - Log.index(X))\n \n print(Log[Log.index(X)+K])\n \nmain()", "from sys import stdin\nimport numpy as np\n \ndef main():\n N, K = [int(x) for x in stdin.readline().rstrip().split()]\n A = [int(x) for x in stdin.readline().rstrip().split()]\n X = 1\n L = [1]\n if A[0] == 1:\n print(1)\n exit()\n if N >= K :\n for i in range(K):\n X = A[X-1]\n print(X)\n exit()\n else:\n for i in range(N):\n X = A[X-1]\n L += [X]\n #print('L',L)#OK\n C = np.zeros(N)\n for i in range(N):\n if C[L[i]-1] == 0:\n C[L[i]-1] += 1\n #print('C,i',C,i)\n else:\n break\n #print('C',C)\n \n #print('L[i+1]',L[i+1])#Roop initial Number\n S = L.index(L[i+1])\n #print('S',S)#When Roop Start ,Roop times\n \n #print('i + 1 -S',i + 1 - S)#Roop Cycle\n K = (K - i-1)%(i+1 - S)\n \n print(L[S+K])\n \nmain()"]
|
['Runtime Error', 'Accepted']
|
['s160888985', 's578544393']
|
[32320.0, 51036.0]
|
[2206.0, 344.0]
|
[487, 1016]
|
p02684
|
u250554058
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\n\nnum = list(map(int, input().split()))\nt = [-1] * n\ncount = 0\ns = 1\n\nwhile t[s - 1] == -1:\n if count == k:\n break\n\n t[s - 1] = count\n count += 1\n s = num[s - 1]\nelse:\n z = (k - t[s - 1]) % (count - t[s - 1])\n print(t.index(t[s - 1] + z + 1)\n', 'n, k = map(int, input().split())\n\nnum = list(map(int, input().split()))\nt = [-1] * n\ncount = 0\ns = 1\n\nwhile t[s - 1] == -1:\n if count == k:\n break\n\n t[s - 1] = count\n count += 1\n s = num[s - 1]\nelse:\n z = (k - t[s - 1]) % (count - t[s - 1])\n s = t.index(t[s - 1] + z + 1)\nprint(s)\n', 'n, k = map(int, input().split())\n\nnum = list(map(int, input().split()))\nt = [-1] * n\ncount = 0\ns = 1\n\nwhile t[s - 1] == -1:\n if count == k:\n break\n\n t[s - 1] = count\n count += 1\n s = num[s - 1]\nelse:\n z = (k - t[s - 1]) % (count - t[s - 1])\n s = t.index(t[s - 1] + z) + 1\nprint(s)\n']
|
['Runtime Error', 'Runtime Error', 'Accepted']
|
['s976399641', 's998146136', 's012466751']
|
[9000.0, 32380.0, 32208.0]
|
[26.0, 161.0, 163.0]
|
[283, 290, 290]
|
p02684
|
u252729807
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\n\n#%%\nans = 0\ntotal = 0\n\nright = 0\nfor left in range(n):\n while total < k: \n if right == n: \n break\n else:\n total += A[right]\n right += 1 \n\n \n if total < k:\n break\n\n ans += n - right + 1 \n total -= A[left] \nprint(ans)', 'n, k = map(int, input().split())\n\nfield = [(i, j) for i, j in zip(range(n), list(map(int, input().split())))]\n\n#%%\ntown = 0 \norder = 0 \nvisited = {town: order} \n\nwhile True:\n trans = field[town][1] - 1 \n n_town = field[trans][0] \n if n_town not in visited.keys():\n order += 1\n visited[n_town] = order \n else: \n st_circ = visited[n_town]\n break\n town = n_town\n\n#%%\n\nvk = list(visited.keys())\nmae = len(vk[:st_circ])\ncirc = len(vk[st_circ:])\n\nif k < mae:\n ans = vk[k]\nelse:\n idx = (k - mae) % circ\n ans = vk[idx + mae]\n\nprint(ans+1)']
|
['Wrong Answer', 'Accepted']
|
['s286804482', 's118701464']
|
[32360.0, 59092.0]
|
[128.0, 277.0]
|
[661, 959]
|
p02684
|
u253389610
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import numpy as np\nfrom itertools import product\nn, m, x = [int(x) for x in input().split()]\na = np.stack([np.array(input().split(), dtype=int) for _ in range(n)])\ntot = np.sum(a, axis=0)\nif min(tot[1:]) < x:\n print(-1)\n exit(0)\ncost = tot[0]\nwhole = np.array(list(product([0,1],repeat=n)), dtype=bool)[1:-1]\nfor flag in whole:\n tot = np.sum(a[flag], axis=0)\n if min(tot[1:]) >= x and tot[0] < cost:\n cost = tot[0]\nprint(cost)\n', 'n, k = [int(x) for x in input().strip().split()]\na = [int(x)-1 for x in input().strip().split()]\nassert len(a) == n\ncurrent = 0\nvisited = [-1] * n\nvisited[0] = 0\nway = [0]\nfor i in range(1, k):\n current = a[current]\n if visited[current] == -1:\n visited[current] = i\n else:\n pre = visited[current]\n count = (k - pre) % (i - pre) + pre\n print(visited.index(count)+1)\nelse:\n print(a[current]+1)\n', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\nassert len(a) == n\ncurrent = 0\nvisited = [-1] * n\nvisited[0] = 0\nfor i in range(1, k):\n current = a[current]\n if visited[current] == -1:\n visited[current] = i\n else:\n pre = visited[current]\n count = (k - pre) % (i - pre) + pre\n print(visited.index(count)+1)\nelse:\n print(a[current]+1)\n', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\nassert len(a) == n\ncurrent = 0\nvisited = [-1] * n\nvisited[0] = 0\nfor i in range(1, k):\n current = a[current]\n if visited[current] == -1:\n visited[current] = i\n else:\n pre = visited[current]\n count = (k - pre) % (i - pre) + pre\n print(visited.index(count)+1)\n break\nelse:\n print(a[current]+1)\n']
|
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
|
['s087781044', 's624095647', 's719090091', 's603690702']
|
[27200.0, 32328.0, 32328.0, 32288.0]
|
[105.0, 2206.0, 2206.0, 122.0]
|
[446, 408, 382, 392]
|
p02684
|
u257265865
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\nnow=1\ncount=0\na=0\nl=[1]\nb=0\nc=0\nq=[True]*N\nwhile a==0and count<K:\n now=A[now-1]\n count+=1\n if q[now-1]:\n a=1\n else:\n l.append(now)\n q[now-1]=False\n \nb=l.index(now)\nc=count-b\nif count==K:\n print(now)\nelse:\n n= ((K-b)%c)\n print(l[b+n])\n\n', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nnow=1\ncount=0\na=0\nl=[1]\nb=0\nc=0\nq=[False]*N\nwhile a==0and count<K:\n now=A[now-1]\n count+=1\n if q[now-1]:\n a=1\n else:\n l.append(now)\n q[now-1]=True\n \nb=l.index(now)\nc=count-b\nif count==K:\n print(now)\nelse:\n n= ((K-b)%c)\n print(l[b+n])\n\n']
|
['Runtime Error', 'Accepted']
|
['s154759639', 's960763544']
|
[32360.0, 32372.0]
|
[70.0, 160.0]
|
[346, 346]
|
p02684
|
u264312747
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['n, k = map(int, input().split())\nx = list(map(int, input().split()))\ncount = 1\nmachi = 0\nmachi_list = [0]\nnext_machi = x[machi] - 1\nmachi_dict = [0] * n\nmachi_dict[0] = 1\nwhile True:\n if machi_dict[next_machi] == 1:\n break\n count += 1\n print(machi_dict)\n machi_dict[next_machi] = 1\n machi_list.append(next_machi)\n machi = next_machi\n next_machi = x[machi] - 1\nz = 0\nfor i in range(0, count):\n if machi_list[i] == next_machi:\n z = i\n break\nloop_machi_list = machi_list[z:]\nif k < z:\n machi = machi_list[k] + 1\n print(machi)\nelse:\n k = k - z\n machi = loop_machi_list[k % len(loop_machi_list)] + 1\n print(machi)', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\ncount = 1\nmachi = 0\nmachi_list = [0]\nnext_machi = x[machi] - 1\nmachi_dict = [0] * n\nmachi_dict[0] = 1\nwhile True:\n if machi_dict[next_machi] == 1:\n break\n count += 1\n machi_dict[next_machi] = 1\n machi_list.append(next_machi)\n machi = next_machi\n next_machi = x[machi] - 1\nz = 0\nfor i in range(0, count):\n if machi_list[i] == next_machi:\n z = i\n break\nloop_machi_list = machi_list[z:]\nif k < z:\n machi = machi_list[k] + 1\n print(machi)\nelse:\n k = k - z\n machi = loop_machi_list[k % len(loop_machi_list)] + 1\n print(machi)']
|
['Wrong Answer', 'Accepted']
|
['s484024075', 's188564509']
|
[142036.0, 32384.0]
|
[2544.0, 174.0]
|
[668, 646]
|
p02684
|
u266014018
| 2,000 | 1,048,576 |
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
|
['import sys\ninput = sys.stdin.buffer.readline\nN, K = map(int, input().split())\nA = list(map(lambda x: int(x)-1, input().split()))\nnow = 0\ndict_ = {}\nstack = []\nfor i in range(N):\n if now not in dict_:\n dict_[now] = A[now]\n stack.append(now)\n now = A[now]\n else:\n idx = stack.index(now)\n mod = i+1 - idx\n break\nidx = idx + (K-idx) % mod\nidx = min(K, idx)\nprint(stack[idx]+1)\n', "def main():\n import sys\n input = sys.stdin.buffer.readline\n N, K = map(int, input().split())\n A = list(map(lambda x: int(x)-1, input().split()))\n now = 0\n dict_ = {}\n stack = []\n for i in range(N):\n if now not in dict_:\n dict_[now] = A[now]\n stack.append(now)\n now = A[now]\n else:\n idx = stack.index(now)\n mod = i - idx\n break\n idx = idx + (K-idx) % mod\n idx = min(K, idx)\n print(stack[idx]+1)\n\n\nif __name__ == '__main__':\n main()\n"]
|
['Runtime Error', 'Accepted']
|
['s120274235', 's899131967']
|
[36912.0, 36964.0]
|
[206.0, 160.0]
|
[421, 547]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.