buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <bits/stdc++.h> //#define int long long int using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N; cin >> N; ll K; cin >> K; vector<ll> v; for (int i = 0; i < N; i++) { ll temp; cin >> temp; temp--; v.push_back(temp); ...
#include <bits/stdc++.h> //#define int long long int using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N; cin >> N; ll K; cin >> K; vector<ll> v; for (int i = 0; i < N; i++) { ll temp; cin >> temp; temp--; v.push_back(temp); ...
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22]]
1
302
#include <algorithm> #include <functional> #include <iomanip> //! for setprecision(10) #include <iostream> #include <math.h> #include <string> #include <vector> #include <cstring> #include <map> #include <queue> #include <set> #include <utility> using namespace std; typedef long long LL; #define dump(c) ...
#include <algorithm> #include <functional> #include <iomanip> //! for setprecision(10) #include <iostream> #include <math.h> #include <string> #include <vector> #include <cstring> #include <map> #include <queue> #include <set> #include <utility> using namespace std; typedef long long LL; #define dump(c) ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
314
N, K = map(int, input().split()) a = list(map(int, input().split())) chk = [0] * N start = -1 ido = [0] chk[0] = 1 index = 0 cnt = 0 while True: index = a[index] - 1 if chk[index] == 0: chk[index] += 1 cnt += 1 ido.append(index) else: start = index break if cnt >= K:...
N, K = map(int, input().split()) a = list(map(int, input().split())) chk = [0] * N start = -1 ido = [0] chk[0] = 1 index = 0 cnt = 0 while True: index = a[index] - 1 if chk[index] == 0: chk[index] += 1 cnt += 1 ido.append(index) else: start = index break if cnt >= K:...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 70], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
151
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; const ll LongINF = 1e13 + 7; const int INF = 1e9 + 7; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; const ll LongINF = 1e13 + 7; const int INF = 1e9 + 7; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; ...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 31, 22], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 31, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
1
557
def solve(N, K, A): slow, fast = 1, 1 is_first = True while is_first or slow != fast: is_first = False slow = A[slow - 1] fast = A[A[fast - 1] - 1] fast = 1 steps_before_entering_cycle = [] while slow != fast: steps_before_entering_cycle.append(slow) slow ...
def solve(N, K, A): slow, fast = 1, 1 is_first = True while is_first or slow != fast: is_first = False slow = A[slow - 1] fast = A[A[fast - 1] - 1] fast = 1 steps_before_entering_cycle = [] while slow != fast: steps_before_entering_cycle.append(fast) slow ...
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 14, 8, 196, 0, 37, 0, 38], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 14, 8, 196, 0, 37, 0, 38], ["+", 0, 656, 0, 14, 8, 196, 0, 37, 0, 22]]
5
203
n,k=map(int,input().split()) A=[int(i) for i in input().split()] went={i:0 for i in range(1,n+1)} now=1 cnt=1 for i in range(n+1): if went[now]>0: t=cnt-1 s=went[now] break else: went[now]=cnt now=A[now-1] cnt+=1 if k <= t: val=k+1 else: val=((k+1-t)%(...
n,k=map(int,input().split()) A=[int(i) for i in input().split()] went={i:0 for i in range(1,n+1)} now=1 cnt=1 for i in range(n+1): if went[now]>0: t=cnt-1 s=went[now] break else: went[now]=cnt now=A[now-1] cnt+=1 if k <= t-1: val=k+1 else: val=((k+1-t)...
[["+", 0, 656, 0, 57, 15, 666, 0, 657, 17, 33], ["+", 0, 656, 0, 57, 15, 666, 0, 657, 12, 612]]
5
168
n, k = gets.split.map!(&:to_i) a = gets.split.map!(&:to_i).unshift(0) x = 1 a1 = 1 a2 = a[a1] while a1 != a2 x += 1 a1 = a[a1] a2 = a[a[a2]] end y = 0 a1 = 1 a2 = a2 while a1 != a2 y += 1 a1 = a[a1] a2 = a[a[a2]] end k = (k - y) % x + y puts k.times.inject(1) { |ai, *| a[ai] }
n, k = gets.split.map!(&:to_i) a = gets.split.map!(&:to_i).unshift(0) x = 1 a1 = 1 a2 = a[a1] while a1 != a2 x += 1 a1 = a[a1] a2 = a[a[a2]] end y = 0 a1 = 1 a2 = a2 while a1 != a2 y += 1 a1 = a[a1] a2 = a[a[a2]] end k = (k - y) % x + y if k >= y puts k.times.inject(1) { |ai, *| a[ai] }
[["+", 36, 36, 36, 36, 0, 493, 0, 751, 0, 121], ["+", 36, 36, 0, 493, 0, 751, 15, 738, 31, 22], ["+", 36, 36, 0, 493, 0, 751, 15, 738, 17, 20], ["+", 36, 36, 0, 493, 0, 751, 15, 738, 12, 22]]
4
127
import sys import math from collections import deque import heapq import itertools MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return input() d...
import sys import math from collections import deque import heapq import itertools MAX_INT = int(10e10) MIN_INT = -MAX_INT mod = 1000000007 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(sys.stdin.readline()) def S(): return input() d...
[["-", 0, 14, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 14, 8, 196, 0, 57, 15, 666, 0, 22]]
5
283
#include "bits/stdc++.h" #include "string.h" using namespace std; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define NFOR(i, a, b) for (ll i = a; i > b; i--) #define sz(a) int((a).size()) #define all(c) c.begin(), c.end() #define loop(c, i) \ for (typ...
#include "bits/stdc++.h" #include "string.h" using namespace std; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define NFOR(i, a, b) for (ll i = a; i > b; i--) #define sz(a) int((a).size()) #define all(c) c.begin(), c.end() #define loop(c, i) \ for (typ...
[["-", 0, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
558
# -*- coding: utf-8 -*- n,k=map(int, input().split()) a=list(map(int, input().split())) isUsed=[False]*n path = [1] #isUsed[0] = True i = 1 while(True): idx = i-1 if isUsed[idx]: #既に行ったことがある町であれば #print("行ったことのある町です") #print("i", i) start = path.index(i) break else: ...
# -*- coding: utf-8 -*- n,k=map(int, input().split()) a=list(map(int, input().split())) isUsed=[False]*n path = [1] #isUsed[0] = True i = 1 while(True): idx = i-1 if isUsed[idx]: #既に行ったことがある町であれば #print("行ったことのある町です") #print("i", i) start = path.index(i) break else: ...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
164
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect ...
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect ...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
391
N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 li = [False] * N f = True now = 0 l = [] l2 = [0] * N i = 0 while f: l.append(now) li[now] = True l2[now] = i if li[A[now]]: f = False num = len(l) - l2[A[now]] n = l2[A[now]] ...
N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 li = [False] * N f = True now = 0 l = [] l2 = [0] * N i = 0 while f: l.append(now) li[now] = True l2[now] = i if li[A[now]]: f = False num = len(l) - l2[A[now]] n = l2[A[now]] ...
[["+", 3, 4, 0, 657, 31, 206, 206, 652, 63, 22], ["+", 0, 657, 31, 206, 206, 652, 3, 4, 0, 24], ["+", 0, 657, 31, 206, 206, 652, 3, 4, 0, 22], ["+", 0, 657, 31, 206, 206, 652, 3, 4, 0, 21], ["+", 0, 657, 31, 206, 206, 652, 3, 4, 0, 25]]
5
159
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" #define ordered_set \ tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, \ tree_order_statistics_node_update> using namespa...
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" #define ordered_set \ tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, \ tree_order_statistics_node_update> using namespa...
[["+", 64, 9, 0, 1, 0, 16, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 12, 13]]
1
425
import math,sys from sys import stdin, stdout from collections import Counter, defaultdict, deque input = stdin.readline I = lambda:int(input()) li = lambda:list(map(int,input().split())) def case(): n,k=li() a=li() d=defaultdict(int) i=0 d[1]=1 c=0 ans=[1] while(a[i] not in d): ...
import math,sys from sys import stdin, stdout from collections import Counter, defaultdict, deque input = stdin.readline I = lambda:int(input()) li = lambda:list(map(int,input().split())) def case(): n,k=li() a=li() d=defaultdict(int) i=0 d[1]=1 c=0 ans=[1] while(a[i] not in d): ...
[["-", 8, 196, 0, 57, 15, 23, 0, 666, 667, 19], ["+", 8, 196, 0, 57, 15, 23, 0, 666, 667, 18], ["-", 15, 23, 0, 666, 0, 652, 3, 4, 0, 22], ["+", 15, 23, 0, 666, 0, 652, 3, 4, 0, 22]]
5
218
N,K=map(int,input().split()) A=list(map(int,input().split())) visited=[0 for i in range(N)] visited[0]=1 tour=[1] while True: goto=A[tour[-1]-1] tour.append(goto) if visited[goto-1]: break visited[goto-1]=1 #print(tour) before=0 shuuki=1 for i in range(len(tour)): if tour[i]==tour[-1]...
N,K=map(int,input().split()) A=list(map(int,input().split())) visited=[0 for i in range(N)] visited[0]=1 tour=[1] while True: goto=A[tour[-1]-1] tour.append(goto) if visited[goto-1]: break visited[goto-1]=1 #print(tour) before=0 shuuki=1 for i in range(len(tour)): if tour[i]==tour[-1]...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 19], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 18], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
173
N,K=map(int,input().split()) A=[0]+list(map(int,input().split())) counter=1 now=1 gone_set={1} gone_list=[1] place=1 while counter<=N: next=A[now] if next in gone_set: start=gone_list.index(next) loop=len(gone_list)-start last=(K-start)%loop place=gone_list[start+last] b...
N,K=map(int,input().split()) A=[0]+list(map(int,input().split())) counter=1 now=1 gone_set={1} gone_list=[1] place=1 while counter<=K: next=A[now] place=next if next in gone_set: start=gone_list.index(next) loop=len(gone_list)-start last=(K-start)%loop place=gone_list[start+...
[["-", 36, 36, 0, 656, 0, 52, 15, 666, 0, 22], ["+", 36, 36, 0, 656, 0, 52, 15, 666, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 662, 12, 22]]
5
130
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int N_MAX = 200005; const int NIL = -1; int TEL[N_MAX + 5]; int A[N_MAX + 5]; int town[N_MAX + 5]; int main() { int n; long long int k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i ...
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int N_MAX = 2000005; const int NIL = -1; int TEL[N_MAX + 5]; int A[N_MAX + 5]; int town[N_MAX + 5]; int main() { int n; long long int k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i...
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 75, 76, 0, 9, 0, 43, 39, 86, 0, 96]]
1
258
n,k=map(int,input().split()) a=list(map(int,input().split())) d={} cnt=[] m=0 ans=0 for i in range(2*n): if a[m] in d: ans+=1 cnt.append(a[m]) if ans==k: print(a[m]) break else: d[a[m]]=0 cnt.append(a[m]) ans+=1 if ans==k: print(a[m]) break m=a[m]-1 if ans!=k: ...
n,k=map(int,input().split()) a=list(map(int,input().split())) d={} cnt=[] m=0 ans=0 for i in range(2*n): if a[m] in d: ans+=1 cnt.append(a[m]) if ans==k: print(a[m]) break else: d[a[m]]=0 cnt.append(a[m]) ans+=1 if ans==k: print(a[m]) break m=a[m]-1 if ans!=k: ...
[["-", 0, 662, 12, 206, 206, 663, 0, 664, 28, 612], ["+", 0, 662, 12, 206, 206, 663, 0, 664, 28, 612]]
5
196
/* LANG:C++ PROB: */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x)...
/* LANG:C++ PROB: */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x)...
[["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
1
506
""" N towns teleporter each town teleporter at town i -> town A_i k-times teleporter after starting at town 1 """ from collections import deque n, k = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) visited = [0] * n path = deque() cur = 0 while not visited[cur]: visited[cur] = 1 ...
""" N towns teleporter each town teleporter at town i -> town A_i k-times teleporter after starting at town 1 """ from collections import deque n, k = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) visited = [0] * n path = deque() cur = 0 while not visited[cur]: visited[cur] = 1 ...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
139
n, k = map(int, input().split()) a = list(map(int, input().split())) move = [a[i] - 1 for i in range(n)] #print(move) d = [-1 for _ in range(n)] d[0] = 0 cur = 0 for _ in range(300000): to = move[cur] if d[to] == -1: d[to] = d[cur] + 1 else: rou = d[cur] + 1 - d[to] rou_start = to ...
n, k = map(int, input().split()) a = list(map(int, input().split())) #n, k = 200000, 100 #a = [i+2 for i in range(n-1)] + [2] move = [a[i] - 1 for i in range(n)] #print(move) d = [-1 for _ in range(n)] d[0] = 0 cur = 0 for _ in range(300000): to = move[cur] if d[to] == -1: d[to] = d[cur] + 1 else: ...
[["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 612]]
5
179
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long K = sc.nextLong(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = sc.nextInt() - 1; } int index = 0; int double_num = -1;...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long K = sc.nextLong(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = sc.nextInt() - 1; } int index = 0; int double_num = -1;...
[["-", 12, 492, 3, 4, 0, 74, 51, 23, 0, 24], ["-", 3, 4, 0, 74, 51, 23, 0, 16, 17, 33], ["-", 3, 4, 0, 74, 51, 23, 0, 16, 12, 499], ["-", 12, 492, 3, 4, 0, 74, 51, 23, 0, 25]]
3
361
import sys n,k = map(int,input().split()) a = list(map(int,input().split())) #各頂点が白(0)か黒(1)か flag = [-1 for _ in range(n)] #dfsで色を塗っていく #頂点の数をN、辺の数をMとすると、O(N+M)で解ける stack = [a[0]-1] flag[0] = 0 count = 0 while stack: u = stack.pop() if flag[u] == -1: stack.append(a[u] - 1) count += 1 if count == k: print(...
import sys n,k = map(int,input().split()) a = list(map(int,input().split())) #各頂点が白(0)か黒(1)か flag = [-1 for _ in range(n)] #dfsで色を塗っていく #頂点の数をN、辺の数をMとすると、O(N+M)で解ける stack = [a[0]-1] flag[0] = 0 count = 0 while stack: u = stack.pop() if flag[u] == -1: stack.append(a[u] - 1) count += 1 if count == k: print(...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 70], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
194
n, k =[int(i) for i in input().split()] a = [int(i) - 1 for i in input().split()] go = dict() res = [] go[0] = True res = [0] now = a[0] while True: if now in go: break res.append(now) go[now] = True now = a[now] # 1 # [0, 1, 2, 3] # (5 - 1) % (xunhuan) amari = res.index(now) xunhuan = res[a...
n, k =[int(i) for i in input().split()] a = [int(i) - 1 for i in input().split()] go = dict() res = [] go[0] = True res = [0] now = a[0] while True: if now in go: break res.append(now) go[now] = True now = a[now] # 1 # [0, 1, 2, 3] # (5 - 1) % (xunhuan) amari = res.index(now) xunhuan = res[a...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
144
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); ...
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); ...
[["-", 0, 30, 0, 43, 49, 50, 51, 16, 31, 13], ["+", 0, 30, 0, 43, 49, 50, 51, 16, 31, 13], ["-", 8, 9, 0, 338, 8, 9, 0, 57, 0, 121], ["-", 0, 338, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["-", 0,...
1
545
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; int N; ll K; int A[200000 + 10]; bool visited[200000 + 10]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; vector<int> cycle; cycle.push_back(0); int pos = 0; visited[0] = tr...
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; int N; ll K; int A[200000 + 10]; bool visited[200000 + 10]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; vector<int> cycle; cycle.push_back(0); int pos = 0; visited[0] = tr...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
248
#include <algorithm> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> #define REP(i, n) for (int i = 0; i < (int)n; i++) #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define REPvec(itr, mp...
#include <algorithm> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> #define REP(i, n) for (int i = 0; i < (int)n; i++) #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define REPvec(itr, mp...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
379
import sys sys.setrecursionlimit(10 ** 6) # 再帰関数の再帰の深さを設定 to_index = lambda x: int(x) - 1 # 入力した数字に1を引いたものを返す print_list_in_2D = lambda x: print(*x, sep="\n") # リストの要素を改行を挟んで表示する関数 # 入力を整数に変換して受け取る def input_int(): return int(input()) def map_int_input(): return map(int, input()) MII = map_int_input def ...
import sys sys.setrecursionlimit(10 ** 6) # 再帰関数の再帰の深さを設定 to_index = lambda x: int(x) - 1 # 入力した数字に1を引いたものを返す print_list_in_2D = lambda x: print(*x, sep="\n") # リストの要素を改行を挟んで表示する関数 # 入力を整数に変換して受け取る def input_int(): return int(input()) def map_int_input(): return map(int, input()) MII = map_int_input def ...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
352
n , k = map(int, input().split()) a = list(map(int,input().split())) v = [0]*(n+1) v[1]=1 v2=[1] i=0 step=1 while True: if v[a[i]]!=0: loop=step-v[a[i]]+1 loopstart=v[a[i]] break else: step+=1 v[a[i]]=step v2.append(a[i]) i=a[i]-1 ans = (k-loopstart+2)%lo...
n , k = map(int, input().split()) a = list(map(int,input().split())) v = [0]*(n+1) v[1]=1 v2=[1] i=0 step=1 while True: if v[a[i]]!=0: loop=step-v[a[i]]+1 loopstart=v[a[i]] break else: step+=1 v[a[i]]=step v2.append(a[i]) i=a[i]-1 ans = (k-loopstart+2)%lo...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
180
#include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (long long i = 0; i < N; ++i) { long long Ai; cin >> Ai; A.at(i) = Ai; } vector<long long> route; route.push_back(0); unordered_m...
#include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (long long i = 0; i < N; ++i) { long long Ai; cin >> Ai; A.at(i) = Ai; } vector<long long> route; route.push_back(0); unordered_m...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
273
#include <bits/stdc++.h> using namespace std; int N; long long K; vector<int> A, T; int main() { cin >> N >> K; A.resize(N + 1); for (int i = 1; i <= N; i++) { cin >> A.at(i); } T.resize(N + 1, -1); int timer = 0; int next = 1; int loop_size, q; while (1) { if (T.at(next) != -1) { loop...
#include <bits/stdc++.h> using namespace std; int N; long long K; vector<int> A, T; int main() { cin >> N >> K; A.resize(N + 1); for (int i = 1; i <= N; i++) { cin >> A.at(i); } T.resize(N + 1, -1); int timer = 0; int next = 1; int loop_size, q; while (1) { if (T.at(next) != -1) { loop...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
1
225
def main(sample_file = ''): """ convenient functions # for i, a in enumerate(iterable) # q, mod = divmod(a, b) # divmod(x, y) returns the tuple (x//y, x%y) # Higher-order function: reduce(operator.mul, xyz_count, 1) # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc...
def main(sample_file = ''): """ convenient functions # for i, a in enumerate(iterable) # q, mod = divmod(a, b) # divmod(x, y) returns the tuple (x//y, x%y) # Higher-order function: reduce(operator.mul, xyz_count, 1) # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc...
[["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
2,400
N, K = map(int, input().split()) A = [int(x) - 1 for x in input().split()] # 最初のループを回るまで loop = 0 city = 0 b = set([0]) while True: loop += 1 if A[city] in b: break else: city = A[city] b.add(city) loop_start = A[city] # ループの始点にたどり着くまで pre = 0 city = 0 while True: pre += 1 ...
N, K = map(int, input().split()) A = [int(x) - 1 for x in input().split()] # 最初のループを回るまで loop = 0 city = 0 b = set([0]) while True: loop += 1 if A[city] in b: break else: city = A[city] b.add(city) loop_start = A[city] # ループの始点にたどり着くまで pre = 0 city = 0 while True: pre += 1 ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 0, 22], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 0, 22]]
5
187
#include <bits/stdc++.h> using namespace std; #define lld long long #define pi pair<int, int> #define pl pair<lld, lld> #define mem0(x) memset(x, 0, sizeof(x)) #define fillnum(x, n) fill(begin(x), end(x), n) #define asort(x) sort(x.begin(), x.end()) #define dsort(x, t) sort(x.begin(), x.end(), greater<t>()) lld N, K;...
#include <bits/stdc++.h> using namespace std; #define lld long long #define pi pair<int, int> #define pl pair<lld, lld> #define mem0(x) memset(x, 0, sizeof(x)) #define fillnum(x, n) fill(begin(x), end(x), n) #define asort(x) sort(x.begin(), x.end()) #define dsort(x, t) sort(x.begin(), x.end(), greater<t>()) lld N, K;...
[["-", 0, 57, 64, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 57, 64, 9, 0, 43, 49, 50, 51, 13], ["-", 64, 9, 0, 52, 15, 339, 51, 16, 17, 60], ["+", 64, 9, 0, 52, 15, 339, 51, 16, 17, 79]]
1
319
#import sys MOD = 10 ** 9 + 7 INFI = 10**10 #input = sys.stdin.readline import math import itertools import heapq #import bisect import copy from functools import lru_cache def sosuhante(n): for k in range(2, int(math.sqrt(n))+1): if n% k ==0: return False return True def cmb(n, r): i...
#import sys MOD = 10 ** 9 + 7 INFI = 10**10 #input = sys.stdin.readline import math import itertools import heapq #import bisect import copy from functools import lru_cache def sosuhante(n): for k in range(2, int(math.sqrt(n))+1): if n% k ==0: return False return True def cmb(n, r): i...
[["-", 0, 14, 8, 196, 0, 57, 15, 666, 667, 19], ["+", 0, 14, 8, 196, 0, 57, 15, 666, 667, 18]]
5
628
#include <bits/stdc++.h> #define pb push_back using namespace std; using ll = long long; using ull = unsigned long long; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<ll>> vvl; typedef vector<vector<string>> vvs; typedef vector<bool> vb; const ll md = 1000000007; vector...
#include <bits/stdc++.h> #define pb push_back using namespace std; using ll = long long; using ull = unsigned long long; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<ll>> vvl; typedef vector<vector<string>> vvs; typedef vector<bool> vb; const ll md = 1000000007; vector...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
1,163
#include <algorithm> #include <iostream> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(A) A.begin(), A.end() ...
#include <algorithm> #include <iostream> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(A) A.begin(), A.end() ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
260
n, k = map(int, input().split()) an = list(map(int, input().split())) group = [0] now = 0 seen = [0]*n seen[0] = 1 while True: now = an[now] - 1 group.append(now) if seen[now] == 1: break seen[now] = 1 l = len(group) a = group.index(group[-1]) roop = l - a - 1 if k < a: print(group[k...
n, k = map(int, input().split()) an = list(map(int, input().split())) group = [0] now = 0 seen = [0]*n seen[0] = 1 while True: now = an[now] - 1 group.append(now) if seen[now] == 1: break seen[now] = 1 l = len(group) a = group.index(group[-1]) roop = l - a - 1 if k < a: print(group[k...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
145
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i], v[i]--; if (k <= n) { int curr = 0; if (k == 0) { cout << curr + 1 << "\n"; exit(0); } int ans = v[curr]; ...
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i], v[i]--; if (k <= n) { int curr = 0; if (k == 0) { cout << curr + 1 << "\n"; exit(0); } int ans = v[curr]; ...
[["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
312
n, k = map(int, input().split()) a = list(map(int, input().split())) flg = True c = [0 for i in range(n)] i = 1 b = [] d = [] one = False while flg: x = i-1 if c[x] == 1 and a[x] == 1: flg = False one = True break elif c[x] == 3: flg = False break else: c[x] += 1 if c[x] == 1: b.append(x+1) if c...
n, k = map(int, input().split()) a = list(map(int, input().split())) flg = True c = [0 for i in range(n)] i = 1 b = [] d = [] one = False while flg: x = i-1 if c[x] == 1 and a[x] == 1: flg = False one = True break elif c[x] == 3: flg = False break else: c[x] += 1 if c[x] == 1: b.append(x+1) if c...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 19], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 18]]
5
211
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; const int MOD = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<bool> flag(n, false); vector<ll> s; vector<ll> cycle; int no...
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; const int MOD = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<bool> flag(n, false); vector<ll> s; vector<ll> cycle; int no...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
251
N, K = map(int, input().split()) A = list(map(int, input().split())) def solve(): visited = [-1]*N visited[0] = 0 goto = 1 counter = 0 period = 0 while 1: counter += 1 #counter 回ワープした goto = A[goto-1] #counter回目につく場所 if counter == K: print(A) ret...
N, K = map(int, input().split()) A = list(map(int, input().split())) def solve(): visited = [-1]*N visited[0] = 0 goto = 1 counter = 0 period = 0 while 1: counter += 1 #counter 回ワープした goto = A[goto-1] #counter回目につく場所 if counter == K: print(goto) ...
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
177
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); ...
[["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
314
n, k = map(int, input().split()) l = list(map(int, input().split())) arr = [] check = [0] * (n + 2) check[1] = 1 c = 0 num = 1 yo = 0 while 1: arr.append(l[c]) if l[c] == 1: yo = 1 break if check[l[c]]: arr.pop() c = l[c] break check[l[c]] = 1 num -= -1 c ...
n, k = map(int, input().split()) l = list(map(int, input().split())) arr = [] check = [0] * (n + 2) check[1] = 1 c = 0 num = 1 yo = 0 while 1: arr.append(l[c]) if l[c] == 1: yo = 1 break if check[l[c]]: arr.pop() c = l[c] break check[l[c]] = 1 num -= -1 c ...
[["+", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["+", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
220
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; using LL = long long; LL n, a[200000], k, now = 0, nowhis[200001]; int main() { nowhis[0] = 0; cin >> n >> k; for (LL i = 0; i < n; i++) { cin >> a[i]; } if (k <= 500...
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; using LL = long long; LL n, a[200000], k, now = 0, nowhis[200001]; int main() { nowhis[0] = 0; cin >> n >> k; for (LL i = 0; i < n; i++) { cin >> a[i]; } if (k <= 500...
[["+", 341, 342, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 341, 342, 0, 16, 31, 16, 31, 23, 0, 25]]
1
210
n,k=map(int,input().split()) A=list(map(int,input().split())) p=1 l=[0]*n #l[0]+=1 if k<=100000: for i in range(k): p=A[p-1] l[p-1]+=1 print(p) exit() else: for i in range(100001): p=A[p-1]#A[0]の番号の町に飛ぶ l[p-1]+=1 #print(p) if l[p-1]==2: x=i ...
n,k=map(int,input().split()) A=list(map(int,input().split())) p=1 l=[0]*n #l[0]+=1 if k<=200000: for i in range(k): p=A[p-1] l[p-1]+=1 print(p) exit() else: for i in range(200001): p=A[p-1]#A[0]の番号の町に飛ぶ l[p-1]+=1 #print(p) if l[p-1]==2: x=i ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 0, 612], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 0, 612], ["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
5
191
#include <bits/stdc++.h> using namespace std; const int MaxN = 200005; int n; long long k; int a[MaxN], depth[MaxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; depth[i] = -1; } depth[1] = 0; int Count = 0...
#include <bits/stdc++.h> using namespace std; const int MaxN = 200005; int n; long long k; int a[MaxN], depth[MaxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; depth[i] = -1; } depth[1] = 0; int Count = 0...
[["-", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22], ["-", 31, 69, 341, 342, 0, 69, 341, 342, 0, 70], ["-", 31, 69, 341, 342, 0, 69, 341, 342, 0, 73]]
1
212
import sys n,k = map(int,input().split()) a = list(map(int,input().split())) array = [-1] * (n+1) array[1] = 0 li = [] li.append(1) tmp = -1 index = 0 for i in range(2 * (10**5)): if array[a[index]] != -1: tmp = array[a[index]] break if i == k: print(index) sys.exit(0) li.append(a[in...
import sys n,k = map(int,input().split()) a = list(map(int,input().split())) array = [-1] * (n+1) array[1] = 0 li = [] li.append(1) tmp = -1 index = 0 for i in range(2 * (10**5)): if array[a[index]] != -1: tmp = array[a[index]] break if i == k: print(index+1) sys.exit(0) li.append(a[...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
172
#include <bits/stdc++.h> using namespace std; #define lli long long #define all(i) i.begin(), i.end() #define rall(i) i.rbegin(), i.rend() #define rep0(i, j) for (int i = 0; i < j; i++) #define rep1(i, j) for (int i = 1; i <= j; i++) #define rep0d(i, j) for (int i = j - 1; i >= 0; i--) #define MOD 1000000007 #define M...
#include <bits/stdc++.h> using namespace std; #define lli long long #define all(i) i.begin(), i.end() #define rall(i) i.rbegin(), i.rend() #define rep0(i, j) for (int i = 0; i < j; i++) #define rep1(i, j) for (int i = 1; i <= j; i++) #define rep0d(i, j) for (int i = j - 1; i >= 0; i--) #define MOD 1000000007 #define M...
[["-", 0, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
1
1,483
/* vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu rtll==??>>;::::~~~~......`.`````````````````` ..J77!`````````...`..._T,~~~~:::;;>??==lttrrv tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` `` .,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! ...
/* vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu rtll==??>>;::::~~~~......`.`````````````````` ..J77!`````````...`..._T,~~~~:::;;>??==lttrrv tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` `` .,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
982
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAX_N = 200005; ll A[MAX_N], cnt[MAX_N], town[MAX_N]; bool visited[MAX_N]; int main() { ll N, K; cin >> N >> K; rep(i, N) { cin >> A[i]; A[i]--; } ll l...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAX_N = 200005; ll A[MAX_N], cnt[MAX_N], town[MAX_N]; bool visited[MAX_N]; int main() { ll N, K; cin >> N >> K; rep(i, N) { cin >> A[i]; A[i]--; } ll l...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
221
#include <stdio.h> long long n, k, s, x, y, z; long long a[200000]; long long c[200000]; int main() { scanf("%lld%lld", &n, &k); for (long long i = 0; i < n; i++) { scanf("%lld", a + i); a[i]--; } y = -1; z = -1; while (z < 0) { s++; c[x]++; if (c[x] == 2 && y < 0) y = s; if (c...
#include <stdio.h> long long n, k, s, x, y, z; long long a[200000]; long long c[200000]; int main() { scanf("%lld%lld", &n, &k); for (long long i = 0; i < n; i++) { scanf("%lld", a + i); a[i]--; } y = -1; z = -1; while (z < 0) { s++; c[x]++; if (c[x] == 2 && y < 0) y = s; if (c...
[["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46]]
1
218
from collections import deque n,k = map(int,input().split()) li = list(map(int,input().split())) for i,l in enumerate(li): li[i]-=1 done = [0]*n root = [] que = deque() done[0] = 1 root.append(0) que.append(li[0]) while(len(que)!=0 and len(root)<k+1): v = que.pop() if done[v]!=0: root.append(v) ...
from collections import deque n,k = map(int,input().split()) li = list(map(int,input().split())) for i,l in enumerate(li): li[i]-=1 done = [0]*n root = [] que = deque() done[0] = 1 root.append(0) que.append(li[0]) while(len(que)!=0 and len(root)<k+1): v = que.pop() if done[v]!=0: root.append(v) ...
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
273
N, K = map(int, input().split()) A = list(map(int, input().split())) went_town = set() now = 1 turn_town = [0] while True: if now-1 in went_town: break else: went_town.add(now-1) now = A[now-1] turn_town.append(now-1) for i in range(len(turn_town)-1): if turn_town[i] == tur...
N, K = map(int, input().split()) A = list(map(int, input().split())) went_town = set() now = 1 turn_town = [0] while True: if now-1 in went_town: break else: went_town.add(now-1) now = A[now-1] turn_town.append(now-1) for i in range(len(turn_town)-1): if turn_town[i] == tur...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
165
#include <bits/stdc++.h> using namespace std; int main() { int n; long long int k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; int isvis[n + 1] = {0}; int j = a[1]; isvis[1] = 1; vector<int> ls; ls.push_back(0); ls.push_back(1); while (!isvis[j]) { isvis[j] = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long int k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; int isvis[n + 1] = {0}; int j = a[1]; isvis[1] = 1; vector<int> ls; ls.push_back(0); ls.push_back(1); while (!isvis[j]) { isvis[j] = ...
[["+", 0, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
221
#include <bits/stdc++.h> using namespace std; int main(void) { // Your code here! long long int i, j, c, k, n; cin >> n >> k; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; vector<long long int> v; set<long long int> s; i = 0; v.push_back(1); s.insert(1); while (true) { i = a[i] ...
#include <bits/stdc++.h> using namespace std; int main(void) { // Your code here! long long int i, j, c, k, n; cin >> n >> k; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; vector<long long int> v; set<long long int> s; i = 0; v.push_back(1); s.insert(1); while (true) { i = a[i] ...
[["-", 341, 342, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 341, 342, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 12, 69, 341, 342, 0, 16, 31, 23, 0, 25], ["+", 12, 69, 341, 342, 0, 16, 31, 23, 0, 25], ["+", 0, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 0, 16, 12, 69, 341, 342, 0, 16, 12, 22]]
1
256
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; ++i) cin >> a[i]; int x = 1, d[n + 1]; bool v[n + 1], exit = false; memset(v, 0, sizeof(v)); v[1] = true; ...
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; ++i) cin >> a[i]; int x = 1, d[n + 1]; bool v[n + 1], exit = false; memset(v, 0, sizeof(v)); v[1] = true; ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
226
#include <algorithm> #include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; int *a = new int[n]; int *arrive = new int[n]; int *city = new int[n]; for (int i = 0; i < n; i++) { city[i] = -1; cin >> a[i]; } int now = 0; city[0] = 0; arrive[0] = 1; long long I...
#include <algorithm> #include <iostream> using namespace std; int main() { long long n, k; cin >> n >> k; int *a = new int[n]; int *arrive = new int[n]; int *city = new int[n]; for (int i = 0; i < n; i++) { city[i] = -1; cin >> a[i]; } int now = 0; city[0] = 0; arrive[0] = 1; long long I...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
241
package main import ( "bufio" "fmt" "io" "log" "os" "strconv" ) func main() { n, k := readInt(), readInt() a := make([]int, n) for i := range a { a[i] = readInt() - 1 } startLoop := -1 exist := make(map[int]bool) root := make([]int, 0) next := 0 for { if _, ok := exist[next]; ok { startLoop = n...
package main import ( "bufio" "fmt" "io" "log" "os" "strconv" ) func main() { n, k := readInt(), readInt() a := make([]int, n) for i := range a { a[i] = readInt() - 1 } startLoop := -1 exist := make(map[int]bool) root := make([]int, 0) next := 0 for { if _, ok := exist[next]; ok { startLoop = n...
[["-", 0, 2, 3, 4, 0, 16, 31, 437, 71, 22], ["+", 0, 2, 3, 4, 0, 16, 31, 437, 71, 22]]
7
821
n,k=(int(i) for i in input().split()) r=[0 for i in range(n)] l=[int(i) for i in input().split()] wazap=[] count=1 saver=None temp=0 while r[temp]==0: r[temp]=count wazap.append(temp) temp=l[temp]-1 start=wazap[-1] for i in range(len(wazap)): if wazap[i]==start-1: left=i break loop=len(wazap)-left if k<...
n,k=(int(i) for i in input().split()) r=[0 for i in range(n)] l=[int(i) for i in input().split()] wazap=[] count=1 saver=None temp=0 while r[temp]==0: r[temp]=count wazap.append(temp) temp=l[temp]-1 start=l[wazap[-1]] left=None for i in range(len(wazap)): if wazap[i]==start-1: left=i break loop=len(waza...
[["+", 0, 656, 0, 1, 0, 662, 12, 206, 51, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 206, 0, 70], ["+", 0, 1, 0, 662, 12, 206, 206, 206, 0, 73], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 685]]
5
164
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #define int long long #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back #define eb emplace_bac...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #define int long long #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back #define eb emplace_bac...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
460
#include <iostream> #include <map> #include <stdint.h> #include <utility> #include <vector> using namespace std; int main() { int64_t N, K; cin >> N >> K; vector<int> A(N + 1, 0); for (int n = 1; n <= N; ++n) { cin >> A[n]; } map<int, int> X; int a = 1; int n; X[1] = 0; for (n = 1; n <= N...
#include <iostream> #include <map> #include <stdint.h> #include <utility> #include <vector> using namespace std; int main() { int64_t N, K; cin >> N >> K; vector<int> A(N + 1, 0); for (int n = 1; n <= N; ++n) { cin >> A[n]; } map<int, int> X; int a = 1; int n; X[1] = 0; for (n = 1; n <= N...
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
232
import sys sys.setrecursionlimit(10000000) N,K = [int(v) for v in input().split()] A = [int(v) for v in input().split()] loop = [] pre = [] visited = set() def dfs(index,now): global pre global loop loop.append(now) if now in visited: for left in range(len(loop)): if now == loop[l...
import sys sys.setrecursionlimit(10000000) N,K = [int(v) for v in input().split()] A = [int(v) for v in input().split()] loop = [] pre = [] visited = set() def dfs(index,now): global pre global loop loop.append(now) if now in visited: for left in range(len(loop)): if now == loop[l...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
182
import sys import math import fractions from collections import deque from collections import defaultdict sys.setrecursionlimit(10**7) N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 visited = set() visited.add(0) trace = [] cur = 0 while True: trace.append(c...
import sys import math import fractions from collections import deque from collections import defaultdict sys.setrecursionlimit(10**7) N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 visited = set() visited.add(0) trace = [] cur = 0 while True: trace.append(c...
[["-", 0, 1, 0, 662, 12, 206, 206, 657, 17, 33], ["-", 0, 1, 0, 662, 12, 206, 206, 657, 12, 612]]
5
214
N,K = (int(x) for x in input().split()) A = list(map(int, input().split())) newlist = [1,A[0]] num = A[0] - 1 ans = [0]*N ans[0] = 1 ans[A[0]-1] = 1 b = 0 c = 0 r = 0 for i in range(10000000000000000000): if(ans[A[num]-1] == 1): b = A[num] break newlist.append(A[num]) ans[A[num]-1] = 1 n...
N,K = (int(x) for x in input().split()) A = list(map(int, input().split())) newlist = [1,A[0]] num = A[0] - 1 ans = [0]*N ans[0] = 1 ans[A[0]-1] = 1 b = 0 c = 0 r = 0 for i in range(K): if(ans[A[num]-1] == 1): b = A[num] break newlist.append(A[num]) ans[A[num]-1] = 1 num = A[num]-1 for i...
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22]]
5
196
from collections import deque N, K = map(int, input().split()) memo = [-1]*(N+1) junban = deque() A = [0]+list(map(int, input().split())) i = 0 x = 1 while memo[x] < 0: junban.append(x) memo[x] = i x = A[x] i += 1 T = i-memo[x] if K < T: print(junban[K]) else: print(list(junban)[memo[x]:][(K-memo[x])%T])
from collections import deque N, K = map(int, input().split()) memo = [-1]*(N+1) junban = deque() A = [0]+list(map(int, input().split())) i = 0 x = 1 while memo[x] < 0: junban.append(x) memo[x] = i x = A[x] i += 1 T = i-memo[x] if K < i: print(junban[K]) else: print(list(junban)[memo[x]:][(K-memo[x])%T])
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 0, 22], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 0, 22]]
5
141
#include <bits/stdc++.h> using namespace std; #define ll long long #define dl double long #define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); ++i) #define rrep(i, m, n) for (ll i = (ll)(m); i > (ll)(n); --i) const ll MOD = 1000000007; const double pi = 3.14159265358979323846; int main(void) { int n, a[200000]; ...
#include <bits/stdc++.h> using namespace std; #define ll long long #define dl double long #define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); ++i) #define rrep(i, m, n) for (ll i = (ll)(m); i > (ll)(n); --i) const ll MOD = 1000000007; const double pi = 3.14159265358979323846; int main(void) { int n, a[200000]; ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
247
#include <bits/stdc++.h> using namespace std; int main() { long N; long K; cin >> N >> K; vector<long> A(N + 1, 0); for (int i = 1; i <= N; i++) { cin >> A[i]; } vector<long> st(N + 1, -1); vector<long> pos(N + 1, -1); long cnt = 0, now = 1; pos[0] = 1; st[1] = 0; bool path = false; while...
#include <bits/stdc++.h> using namespace std; int main() { long N; long K; cin >> N >> K; vector<long> A(N + 1, 0); for (int i = 1; i <= N; i++) { cin >> A[i]; } vector<long> st(N + 1, -1); vector<long> pos(N + 1, -1); long cnt = 0, now = 1; pos[0] = 1; st[1] = 0; bool path = false; while...
[["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 70], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 73]]
1
237
// Problem : D - Teleporter // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // #pragma optimize("03") #include <bits/stdc++.h> #include <ext/p...
// Problem : D - Teleporter // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // #pragma optimize("03") #include <bits/stdc++.h> #include <ext/p...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
476
n,k = gets.split.map &:to_i as = gets.split.map &:to_i check = Array.new(n+1, false) trail = [] pos = 0 (n + 1).times{ if check[pos] then loop_start = trail.find_index(pos) loop_end = trail.size loop_size = loop_end - loop_start if k <= loop_start then puts trail[k - 1] + 1 else step = (k - loop_...
n,k = gets.split.map &:to_i as = gets.split.map &:to_i check = Array.new(n+1, false) trail = [] pos = 0 (n + 1).times{ if check[pos] then loop_start = trail.find_index(pos) loop_end = trail.size loop_size = loop_end - loop_start if k <= loop_start then puts trail[k] + 1 else step = (k - loop_star...
[["-", 3, 4, 0, 738, 31, 742, 0, 738, 17, 33], ["-", 3, 4, 0, 738, 31, 742, 0, 738, 12, 612]]
4
126
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] -= 1 d = {0} p = 0 while not a[p] in d: d.add(a[p]) p = a[p] #print(d) val = [0] p = 0 for i in range(len(d)): val.append(a[p]) p = a[p] #print(val) cnt = 0 p = 0 while val[p] != val[-1]: cnt += 1 p ...
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] -= 1 d = {0} p = 0 while not a[p] in d: d.add(a[p]) p = a[p] #print(d) val = [0] p = 0 for i in range(len(d)): val.append(a[p]) p = a[p] #print(val) cnt = 0 p = 0 while val[p] != val[-1]: cnt += 1 p ...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
187
#include <bits/stdc++.h> #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; using namespace std; int main() { ll n, k; cin >> n >> k; vector<ll> a(n), b(n, 0); rep(i, n) { cin >> a[i]; a[i]--; } ll next = 0, lp = 0; bool l = 1; ...
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; using namespace std; int main() { ll n, k; cin >> n >> k; vector<ll> a(n), b(n, 0); rep(i, n) { cin >> a[i]; a[i]--; } ll next = 0, lp = 0; bool l = 1; ...
[["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32]]
1
174
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int N, K; cin >> N >> K; vector<int> A(N + 1); map<int, int> m; for (int i = 1; i <= N; i++) { cin >> A[i]; } int town = 1; int s, e; int tmp; m[1] = 0; town = A[1]; for (int i = 1; i <= N; i++) { ...
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int N, K; cin >> N >> K; vector<int> A(N + 1); map<int, int> m; for (int i = 1; i <= N; i++) { cin >> A[i]; } int town = 1; int s, e; int tmp; m[1] = 0; town = A[1]; for (int i = 1; i <= N; i++) { ...
[["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 22], ["+", 64, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 64, 9, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 0, 9, 0, 7, 10, 43, 49, 50, 51, 22], ["+", 0, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
286
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; #ifndef ONLINE_JUDGE template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; #ifndef ONLINE_JUDGE template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; ...
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
769
#include <bits/stdc++.h> using namespace std; #define fastIO \ std::ios_base::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout.tie(0) #define rep(...
#include <bits/stdc++.h> using namespace std; #define fastIO \ std::ios_base::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout.tie(0) #define rep(...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
451
def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) flag = [False] * N flag[0] = True move = [0] num = 0 while True: num += 1 c_next = A[move[-1]]-1 move.append(c_next) if flag[c_next]: break else: flag[c_next] = True for i, j in enumerate(mo...
def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) flag = [False] * N flag[0] = True move = [0] num = 0 while True: num += 1 c_next = A[move[-1]]-1 move.append(c_next) if flag[c_next]: break else: flag[c_next] = True for i, j in enumerate(mo...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
173
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; vector<int> a(n + 1); rep(i, n) { cin >> a[i + 1]; } vector<int> num(n + 1); ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; vector<int> a(n + 1); rep(i, n) { cin >> a[i + 1]; } vector<int> num(n + 1); ...
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
210
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <cstring> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <ostream> #include <queue> #include <set> #include <stack> #include <time.h> using namespace std; #define ll long long const int N = 2e5 + 10;...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <cstring> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <ostream> #include <queue> #include <set> #include <stack> #include <time.h> using namespace std; #define ll long long const int N = 2e5 + 10;...
[["-", 8, 9, 0, 7, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 15, 16, 31, 16, 12, 16, 31, 13], ["+", 0, 7, 15, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 7, 15, 16, 31, 16, 12, 16, 12, 13]]
1
218
"use strict"; var input = require("fs").readFileSync("/dev/stdin", "utf8"); var cin = input.split(/ |\n/), cid = 0; function next(a) { return a ? cin[cid++] : +cin[cid++]; } function nexts(n, a) { return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a); } function nextm(h, w, a) { var r = [], i ...
"use strict"; var input = require("fs").readFileSync("/dev/stdin", "utf8"); var cin = input.split(/ |\n/), cid = 0; function next(a) { return a ? cin[cid++] : +cin[cid++]; } function nexts(n, a) { return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a); } function nextm(h, w, a) { var r = [], i ...
[["+", 51, 2, 3, 3, 0, 2, 3, 3, 0, 555]]
2
430
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; #define ll long long #define ld long double #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265358979323846 #define sz(x) ((int)(x).size()) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const int INF =...
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; #define ll long long #define ld long double #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265358979323846 #define sz(x) ((int)(x).size()) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) const int INF =...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 74, 0, 24], ["+", 31, 16, 12, 16, 12, 74, 39, 77, 39, 78], ["+", 0, 16, 31, 16, 12, 16, 12, 74, 0, 2...
1
368
n,k=map(int,input().split()) A=list(map(int,input().split())) a=[0]*n a[0]=1 nxt=A[0]-1 i=2 while 1: a[nxt]=i nxt=A[nxt]-1 i+=1 if a[nxt]!=0: g=i-a[nxt] t=a[nxt]-1 break if t>=k: print(a.index(k)) else: k-=t u=k%g print(a.index(t+u+1)+1)
n,k=map(int,input().split()) A=list(map(int,input().split())) a=[0]*n a[0]=1 nxt=A[0]-1 i=2 while 1: a[nxt]=i nxt=A[nxt]-1 i+=1 if a[nxt]!=0: g=i-a[nxt] t=a[nxt]-1 break if t>=k: print(a.index(k+1)+1) else: k-=t u=k%g print(a.index(t+u+1)+1)
[["+", 0, 657, 31, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 657, 31, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
141
#include <bits/stdc++.h> using namespace std; constexpr long long int mod = 1000000007; int main() { long long N, K; cin >> N >> K; vector<long long> Jump(N); for (size_t i = 0; i < N; i++) { cin >> Jump.at(i); Jump.at(i)--; } vector<long long> Firstcome(N, -1); long long now = 0; long long l...
#include <bits/stdc++.h> using namespace std; constexpr long long int mod = 1000000007; int main() { long long N, K; cin >> N >> K; vector<long long> Jump(N); for (size_t i = 0; i < N; i++) { cin >> Jump.at(i); Jump.at(i)--; } vector<long long> Firstcome(N, -1); long long now = 0; long long l...
[["+", 64, 9, 0, 1, 0, 16, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 12, 13]]
1
298
# frozen_string_literal: true n, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) h = Hash.new a.each_with_index do |e, i| h[i + 1] = e end c = [1] i = 1 hh = Hash.new { false } ind = 0 hh[1] = true loop do i = h[i] if hh[i] ind = c.index(i) break end c.push i hh[i] = true end if k <= c.size...
# frozen_string_literal: true n, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) h = Hash.new a.each_with_index do |e, i| h[i + 1] = e end c = [1] i = 1 hh = Hash.new { false } ind = 0 hh[1] = true loop do i = h[i] if hh[i] ind = c.index(i) break end c.push i hh[i] = true end if k <= c.size ...
[["+", 3, 4, 0, 742, 500, 742, 0, 475, 17, 757], ["-", 0, 652, 3, 4, 0, 742, 0, 738, 17, 72], ["+", 0, 652, 3, 4, 0, 742, 500, 742, 0, 73], ["+", 75, 95, 0, 652, 3, 4, 0, 742, 0, 70], ["-", 12, 738, 31, 739, 0, 738, 31, 738, 17, 72], ["-", 12, 738, 31, 739, 0, 738, 31, 738, 12, 612]]
4
145
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, a, b) for ((i...
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, a, b) for ((i...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
382
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return...
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return...
[["-", 8, 196, 0, 1, 0, 662, 12, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 206, 51, 22]]
5
457
#include <algorithm> #include <array> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <regex> #include <set>...
#include <algorithm> #include <array> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <regex> #include <set>...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 15, 339, 51, 16, 12, 16, 31, 2, 63, 22], ["+", 51, 16, 12, 16, 31, 2, 3, 4, 0, 24], ["+", 51, 16, 12, 16, 31, 2, 3, 4, 0, 22], ["+", 51, 16, 12, 16, 31, 2, 3, 4, 0, 25]]
1
780
#define ll long long #include <bits/stdc++.h> using namespace std; ll n, t[2000005]; vector<ll> v; set<ll> s; ll k; int main() { cin >> n; // scanf("%lld", &k); cin >> k; for (int i = 0; i < n; ++i) { cin >> t[i + 1]; // scanf("%d", &t[i+1]); } ll x = t[1], cycle = 1; v.push_back(1); s.insert(...
#define ll long long #include <bits/stdc++.h> using namespace std; ll n, t[2000005]; vector<ll> v; set<ll> s; ll k; int main() { cin >> n; // scanf("%lld", &k); cin >> k; for (int i = 0; i < n; ++i) { cin >> t[i + 1]; // scanf("%d", &t[i+1]); } ll x = t[1], cycle = 1; v.push_back(1); s.insert(...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
238
#include <algorithm> #include <climits> #include <cmath> #include <iostream> #include <numeric> #include <unordered_map> #include <vector> constexpr int SINT_MAX = std::numeric_limits<int>::max(); constexpr int SINT_MIN = std::numeric_limits<int>::min(); #define YesNo(b) ((b) ? "Yes" : "No") #define YESNO(b) ((b) ? "...
#include <algorithm> #include <climits> #include <cmath> #include <iostream> #include <numeric> #include <unordered_map> #include <vector> constexpr int SINT_MAX = std::numeric_limits<int>::max(); constexpr int SINT_MIN = std::numeric_limits<int>::min(); #define YesNo(b) ((b) ? "Yes" : "No") #define YESNO(b) ((b) ? "...
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["-", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22]]
1
298
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) ...
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) ...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
444
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007 #define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++) #define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++) #define repi(i, n) for (ll(i) = 0LL; (i) <= (l...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007 #define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++) #define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++) #define repi(i, n) for (ll(i) = 0LL; (i) <= (l...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
587
#include <bits/stdc++.h> using namespace std; int i, j, k, x, y, z, l, m, n, count1 = 0, count2 = 0; int gcd(int, int); void A(void); void B(void); void C(void); void D(void); void E(void); void F(void); int main(void) { D(); } void D() { long long int k; int next, d = 0; int t = 0, t2 = 0; cin >> n >> k; v...
#include <bits/stdc++.h> using namespace std; int i, j, k, x, y, z, l, m, n, count1 = 0, count2 = 0; int gcd(int, int); void A(void); void B(void); void C(void); void D(void); void E(void); void F(void); int main(void) { D(); } void D() { long long int k; int next, d = 0; int t = 0, t2 = 0; cin >> n >> k; v...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
377
def main(): N,K = map(int, input().split()) A = list(map(int, input().split())) A.insert(0,0) B = [0]*(N+1) tel = 1 telmae = 1 for i in range(K): if B[tel] ==0: B[tel] = i telmae = tel tel = A[tel] else: temp = i - B[tel] ...
def main(): N,K = map(int, input().split()) A = list(map(int, input().split())) A.insert(0,0) B = [0]*(N+1) tel = 1 telmae = 1 for i in range(K): if B[tel] ==0: B[tel] = i telmae = tel tel = A[tel] else: temp = i - B[tel] ...
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
152
#include <algorithm> #include <cctype> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) typedef int long long ll;...
#include <algorithm> #include <cctype> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) typedef int long long ll;...
[["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
1
459
import sys sys.setrecursionlimit(10**6) from math import floor,ceil,sqrt,factorial,log from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect...
import sys sys.setrecursionlimit(10**6) from math import floor,ceil,sqrt,factorial,log from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
426
/*Whose woods these are I think I know. His house is in the village though; He will not see me stopping here To watch his woods fill up with snow. My little horse must think it queer To stop without a farmhouse near Between the woods and frozen lake The darkest evening of the year. He gives his harness bells a shake ...
/*Whose woods these are I think I know. His house is in the village though; He will not see me stopping here To watch his woods fill up with snow. My little horse must think it queer To stop without a farmhouse near Between the woods and frozen lake The darkest evening of the year. He gives his harness bells a shake ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
352
#include <algorithm> #include <array> #include <atomic> #include <bitset> #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <chrono> #include <cinttypes> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <condition_var...
#include <algorithm> #include <array> #include <atomic> #include <bitset> #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <chrono> #include <cinttypes> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <condition_var...
[["+", 8, 9, 0, 1, 0, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 16, 12, 16, 12, 13]]
1
675
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (long long i = 0; i < N; i++) { cin >> A[i]; } unordered_map<int, int> teleport; long long idx = 1; long long count = 1; long long prev_idx = 0; for (; count <= K; count++) {...
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (long long i = 0; i < N; i++) { cin >> A[i]; } unordered_map<int, int> teleport; long long idx = 1; long long count = 1; long long prev_idx = 0; for (; count <= K; count++) {...
[["-", 51, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 12, 13], ["-", 51, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
1
206
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; typedef long long int llint; int main() { llint N, K; cin >> N >> K; int A[N]; bool visited[N]; for (int i = 0; i < N; i++) { cin >> A[i]; A[i]--; visited[i] = false;...
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; typedef long long int llint; int main() { llint N, K; cin >> N >> K; int A[N]; bool visited[N]; for (int i = 0; i < N; i++) { cin >> A[i]; A[i]--; visited[i] = false;...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
223
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define ll long long int #define M 1000000007 int mai...
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <set> #include <string> #include <utility> #include <vector> using namespace std; #define ll long long int #define M 1000000007 int mai...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 3...
1
282
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define ...
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define ...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
1
313