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 INF 0x3f3f3f3f using namespace std; typedef long long ll; const int maxn = 2e5 + 7; int n, a[maxn]; ll k; set<int> sp; int p[maxn], tot; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sp.insert(1); int cur = 1, last = -1; p[++tot] = ...
#include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; const int maxn = 2e5 + 7; int n, a[maxn]; ll k; set<int> sp; int p[maxn], tot; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sp.insert(1); int cur = 1, last = -1; p[++tot] = ...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 17, 72], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
283
import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline def main(): N, K = map(int, readline().split()) A = list(map(int, readline().split())) lenA = len(A) tmp = [] path = [] setpath = set([]) cnt = 0 i = 1 for _ in range(1, N+10): setpath.add(i) pat...
import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline def main(): N, K = map(int, readline().split()) A = list(map(int, readline().split())) lenA = len(A) tmp = [] path = [] setpath = set([]) cnt = 0 i = 1 for _ in range(1, N+10): setpath.add(i) pat...
[["-", 0, 1, 0, 662, 12, 206, 206, 657, 17, 33], ["-", 0, 1, 0, 662, 12, 206, 206, 657, 12, 612]]
5
195
// #include <bits/stdc++.h> #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned long long ull; #define FOR(i, a, b) for (int i = (a); i < (b); ++i...
// #include <bits/stdc++.h> #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned long long ull; #define FOR(i, a, b) for (int i = (a); i < (b); ++i...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
777
n, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) b = [false] * n # ループになってるところを探す visit = [] place = 1 loop do b[place - 1] = true visit << place place = a[place - 1] break if b[place - 1] end lstrt = visit.find_index place steps = visit[0...lstrt] cycle = visit - steps if k < lstrt + 1 puts step...
n, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) b = [false] * n # ループになってるところを探す visit = [] place = 1 loop do b[place - 1] = true visit << place place = a[place - 1] break if b[place - 1] end lstrt = visit.find_index place steps = visit[0...lstrt] cycle = visit - steps if k < lstrt puts steps[k]...
[["-", 0, 493, 0, 121, 15, 738, 12, 738, 17, 72], ["-", 0, 493, 0, 121, 15, 738, 12, 738, 12, 612]]
4
116
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define REP(i, n) for (int i = 0; i < n; i++) using Gr...
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define REP(i, n) for (int i = 0; i < n; i++) using Gr...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
284
#include <bits/stdc++.h> using namespace std; typedef long long int ll; void dfs(int i, vector<ll> &v, vector<int> &visited, vector<ll> &aux, ll &element) { visited[i] = 1; aux.push_back(i); if (visited[v[i]]) { element = v[i]; return; } else { dfs(v[i], v, visited, aux, element); } } in...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; void dfs(int i, vector<ll> &v, vector<int> &visited, vector<ll> &aux, ll &element) { visited[i] = 1; aux.push_back(i); if (visited[v[i]]) { element = v[i]; return; } else { dfs(v[i], v, visited, aux, element); } } in...
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
363
import sys import itertools import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K = map(int, readline().split()) A = list(map(lambda x: x - 1, map(int, readline().split()))) visited = [False for i in range(N)] cur = 0 cycle = [] start = 0 wh...
import sys import itertools import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K = map(int, readline().split()) A = list(map(lambda x: x - 1, map(int, readline().split()))) visited = [False for i in range(N)] cur = 0 cycle = [] start = 0 wh...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 206, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 206, 22]]
5
202
from collections import deque n, k = list(map(int, input().split())) a = [0, ] + list(map(int, input().split())) stack = deque([1, ]) visited = [0] * (n + 1) hist = [] open = [] loop = [] while stack: now = stack.popleft() if visited[now] == 1: b = hist.index(now) open = hist[:b] loop = ...
from collections import deque n, k = list(map(int, input().split())) a = [0, ] + list(map(int, input().split())) stack = deque([1, ]) visited = [0] * (n + 1) hist = [] open = [] loop = [] while stack: now = stack.popleft() if visited[now] == 1: b = hist.index(now) open = hist[:b] loop = ...
[["-", 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, 21], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
184
from collections import defaultdict def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) town = defaultdict(int) cn = defaultdict(int) visited = set() visited.add(0) cnt = 0 tmp = A[0]-1 town[cnt] = 0 ii = 0 while True: if(tmp n...
from collections import defaultdict def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) town = defaultdict(int) cn = defaultdict(int) visited = set() visited.add(0) cnt = 0 tmp = A[0]-1 town[cnt] = 0 ii = 0 while True: if(tmp n...
[["-", 8, 196, 0, 57, 15, 23, 0, 666, 667, 47], ["+", 8, 196, 0, 57, 15, 23, 0, 666, 667, 20]]
5
213
n, k = map(int, input().split()) a = list(map(int, input().split())) a = [i - 1 for i in a] g = [-1] * n i = 0 j = 0 while g[j] == -1: if i == k: print(a[j]) exit() g[j] = i i += 1 j = a[j] for i in range((k - g[j]) % (i - g[j])): j = a[j] print(j + 1)
n, k = map(int, input().split()) a = list(map(int, input().split())) a = [i - 1 for i in a] g = [-1] * n i = 0 j = 0 while g[j] == -1: if i == k: print(j + 1) exit() g[j] = i i += 1 j = a[j] for i in range((k - g[j]) % (i - g[j])): j = a[j] print(j + 1)
[["-", 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
133
#include <iostream> #include <vector> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); vector<bool> visited(N, false); vector<long long> F(N, 0); for (long long i = 0; i < N; i++) { cin >> A[i]; A[i]--; } long long cnt1 = N > K ? K : N; long long now...
#include <iostream> #include <vector> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); vector<bool> visited(N, false); vector<long long> F(N, 0); for (long long i = 0; i < N; i++) { cin >> A[i]; A[i]--; } long long cnt1 = N > K ? K : N; long long now...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 13]]
1
299
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[] in = new int[n]; long[] count = new long[n]; for (int i = 0; i < n; i++) { in[i] = sc.nextInt(); } count[0] = ...
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[] in = new int[n]; long[] count = new long[n]; for (int i = 0; i < n; i++) { in[i] = sc.nextInt(); } count[0] = ...
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 504, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 504, 0, 73]]
3
295
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int n; unsigned long int k; int *a, *cntr; cin >> n >> k; a = new int[2 * n]; cntr = a + n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cntr[i] = 0; } int crt_twn = 1; int roop_...
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int n; unsigned long int k; int *a, *cntr; cin >> n >> k; a = new int[2 * n]; cntr = a + n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cntr[i] = 0; } int crt_twn = 1; unsigned ...
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 87], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
243
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i <...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define rep2(i, s, n) for (int i = (s); i <...
[["+", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
271
N , K = map(int,input().split()) B = {} C = {} D = {0} A = list(map(int,input().split())) place = 0 num = 0 C[0] = 0 while True: place = int(A[place]) - 1 num += 1 if place in D: Y = int(num) - int(C[place]) break elif num == K: break else: B[num] = place C...
N , K = map(int,input().split()) B = {} C = {} D = {0} A = list(map(int,input().split())) place = 0 num = 0 C[0] = 0 while True: place = int(A[place]) - 1 num += 1 if place in D: Y = int(num) - int(C[place]) break elif num == K: break else: B[num] = place C...
[["-", 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
155
// OPTIMIZATONS #pragma GCC optimize("02") // CODE #include <bits/stdc++.h> #define int long long #define float double #define endl "\n" #define debug cout << "Good uptill here" << endl << flush; #define deb(x) cout << #x << ":" << x << endl << flush; using namespace std; const int N = 2e5 + 1; int edg[N] = {0}; bool ...
// OPTIMIZATONS #pragma GCC optimize("02") // CODE #include <bits/stdc++.h> #define int long long #define float double #define endl "\n" #define debug cout << "Good uptill here" << endl << flush; #define deb(x) cout << #x << ":" << x << endl << flush; using namespace std; const int N = 2e5 + 1; int edg[N] = {0}; bool ...
[["+", 64, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 12, 13]]
1
295
n , k = map(int,input().split()) S = list(map(int,input().split())) l = [1] for i in range(2*n): l.append(S[l[i]-1]) L = len(l) def f(s, e): a = s b = s while True: a += 2 b += 1 if a >= e: return None if l[a] == l[b]: break a = 0 while ...
n , k = map(int,input().split()) S = list(map(int,input().split())) l = [1] for i in range(2*n): l.append(S[l[i]-1]) L = len(l) def f(s, e): a = s b = s while True: a += 2 b += 1 if a >= e: return None if l[a] == l[b]: break a = 0 while ...
[["-", 12, 657, 31, 23, 0, 657, 31, 657, 12, 22], ["-", 0, 662, 12, 657, 31, 23, 0, 657, 17, 33], ["-", 0, 662, 12, 657, 31, 23, 0, 657, 12, 612], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 12, 22], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
212
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int N = 200010; int a[N]; bool st[N]; int ans[N]; int main() { int n; long long k; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } st[1] = true; int x = 1; int num = 0; ans[1] = ...
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int N = 200010; int a[N]; bool st[N]; int ans[N]; int main() { int n; long long k; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } st[1] = true; int x = 1; int num = 0; ans[1] = ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
302
N, K = map(int, input().split()) A = list(map(int, input().split())) visited = [0] * N order = [] cur = 1 cnt = 0 while True: if visited[cur-1] == 0: visited[cur-1] += 1 if cnt == K: print(cur) elif visited[cur-1] == 1: # cur == 2 order_from_cur = order[order.i...
N, K = map(int, input().split()) A = list(map(int, input().split())) visited = [0] * N order = [] cur = 1 cnt = 0 while True: if visited[cur-1] == 0: visited[cur-1] += 1 if cnt == K: print(cur) break elif visited[cur-1] == 1: # cur == 2 order_from_c...
[["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
5
143
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = long long; int main() { ll N, K; cin >> N >> K; vector<ll> A(N + 1); for (ll i = 1; i <= N; i++) { cin >> A[i]; } ll now = 1; ll loop_len = 1; ll i; vector<ll> loop_check(N + 1, -1); loop_check[1] = 0; for (i = ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = long long; int main() { ll N, K; cin >> N >> K; vector<ll> A(N + 1); for (ll i = 1; i <= N; i++) { cin >> A[i]; } ll now = 1; ll loop_len = 1; ll i; vector<ll> loop_check(N + 1, -1); loop_check[1] = 0; for (i = ...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
205
from copy import copy, deepcopy from collections import Counter from math import sqrt, floor, factorial from itertools import permutations, combinations, combinations_with_replacement from operator import mul from functools import reduce import bisect MOD = 10**9 + 7 INF = float('inf') N, K = list(map(int, input().sp...
from copy import copy, deepcopy from collections import Counter from math import sqrt, floor, factorial from itertools import permutations, combinations, combinations_with_replacement from operator import mul from functools import reduce import bisect MOD = 10**9 + 7 INF = float('inf') N, K = list(map(int, input().sp...
[["+", 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], ["-", 0, 7, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 8, 196, 0, 1, 0, 662, 12, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 206, 206, 22]]
5
247
#include <bits/stdc++.h> #define Phuong_ \ ios_base::sync_with_stdio(0); \ cin.tie(0); /// easy access ------------- using namespace std; using ll = long long; using ld = long double; typedef pair<int, int...
#include <bits/stdc++.h> #define Phuong_ \ ios_base::sync_with_stdio(0); \ cin.tie(0); /// easy access ------------- using namespace std; using ll = long long; using ld = long double; typedef pair<int, int...
[["+", 0, 57, 64, 1, 0, 16, 12, 16, 17, 72], ["+", 0, 57, 64, 1, 0, 16, 12, 16, 12, 13]]
1
231
# coding:utf-8 import sys import math import time #import numpy as np import collections from collections import deque from collections import Counter import queue import copy import bisect import heapq import itertools sys.setrecursionlimit(10**7) #N, Q = map(int, input().split()) #G = [list(input()) for i in rang...
# coding:utf-8 import sys import math import time #import numpy as np import collections from collections import deque from collections import Counter import queue import copy import bisect import heapq import itertools sys.setrecursionlimit(10**7) #N, Q = map(int, input().split()) #G = [list(input()) for i in rang...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 0, 70], ["+", 3, 4, 0, 206, 206, 657, 31, 206, 0, 73], ["+", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["+", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
270
/// author: Mr.Hakimov #include <bits/stdc++.h> #include <chrono> #define fi first #define se second #define pb push_back #define pf push_front #define Pb pop_back #define Pf pop_front #define all(x) (x).begin(), (x).end() #define fin(s) freopen(s, "r", stdin); #define fout(s) freopen(s, "w", stdout); using namespac...
/// author: Mr.Hakimov #include <bits/stdc++.h> #include <chrono> #define fi first #define se second #define pb push_back #define pf push_front #define Pb pop_back #define Pf pop_front #define all(x) (x).begin(), (x).end() #define fin(s) freopen(s, "r", stdin); #define fout(s) freopen(s, "w", stdout); using namespac...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
436
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long int; using vec = vector<int>; using P = pair<int, int>; int main() { ll n, k; cin >> n >> k; vec a(n); vec f(n, -1); rep(i, n) { cin >> a[i]; a[i]--; } int c = 0; int b = 0; whi...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long int; using vec = vector<int>; using P = pair<int, int>; int main() { ll n, k; cin >> n >> k; vec a(n); vec f(n, -1); rep(i, n) { cin >> a[i]; a[i]--; } int c = 0; int b = 0; whi...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342...
1
221
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
461
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n; long long int k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n; long long int k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool ...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
291
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <st...
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <st...
[["-", 3, 4, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13]]
1
671
#include <bits/stdc++.h> using namespace std; static const long long MOD = 1000000000 + 7; int main() { long long n, k; cin >> n >> k; vector<long long> A(n + 1); for (int i = 1; i < n + 1; i++) { cin >> A.at(i); } if (n >= k) { long long now = 1; for (int i = 0; i < n; i++) { now = A.at...
#include <bits/stdc++.h> using namespace std; static const long long MOD = 1000000000 + 7; int main() { long long n, k; cin >> n >> k; vector<long long> A(n + 1); for (int i = 1; i < n + 1; i++) { cin >> A.at(i); } if (n >= k) { long long now = 1; for (int i = 0; i < k; i++) { now = A.at...
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22]]
1
265
#define _LIBCPP_DEBUG 0 #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1e9 + 7; int INF = 1 << 30; int main(void) { ll N, K; cin >> N >> K; vector<ll> A(N + 1, 0); vector<ll> check(N + 1, 0); vector<pair<ll, ll>> visited; for (int i = 1; i <= N; ++i) { cin >> A[i]; ...
#define _LIBCPP_DEBUG 0 #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1e9 + 7; int INF = 1 << 30; int main(void) { ll N, K; cin >> N >> K; vector<ll> A(N + 1, 0); vector<ll> check(N + 1, 0); vector<pair<ll, ll>> visited; for (int i = 1; i <= N; ++i) { cin >> A[i]; ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
316
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { Main mainObj = new Main(); mainObj.solve(); } ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { Main mainObj = new Main(); mainObj.solve(); } ...
[["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 12, 499]]
3
637
#include <bits/stdc++.h> using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } map<int, int> arrive; vector<bool> checked(n, false); vector<int> route; int now = 0; int count = 0; while (count < k) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } map<int, int> arrive; vector<bool> checked(n, false); vector<int> route; int now = 0; int count = 0; while (count < k) { ...
[["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
195
#include <iostream> #include <string> #include <tuple> using namespace std; typedef long long ll; typedef long double ld; #define int ll #define loop(i, n) for (int i = 0; i < n; ++i) #define loop1(i, n) for (int i = 1; i < n; ++i) #define ti tuple<int, int, int> const int INF = 1e9 + 7; void solve() { int n, k;...
#include <iostream> #include <string> #include <tuple> using namespace std; typedef long long ll; typedef long double ld; #define int ll #define loop(i, n) for (int i = 0; i < n; ++i) #define loop1(i, n) for (int i = 1; i < n; ++i) #define ti tuple<int, int, int> const int INF = 1e9 + 7; void solve() { int n, k;...
[["-", 0, 9, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 13], ["-", 0, 9, 0, 1, 0, 11, 12, 23, 0, 25]]
1
275
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); ++(i)) #define dump(x) cout << #x << " = " << (x) << endl using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; a[i]--; } vector<bool> seen(n, false); vector...
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); ++(i)) #define dump(x) cout << #x << " = " << (x) << endl using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; a[i]--; } vector<bool> seen(n, false); vector...
[["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 25], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
284
N,K = map(int,input().split()) A = list(map(int,input().split())) towns = [0] * N town = 1 i = 0 while True: if towns[town-1] < 2: if towns[town-1] == 0: i += 1 towns[town-1] += 1 town = A[town-1] else: s = town break loop = towns....
N,K = map(int,input().split()) A = list(map(int,input().split())) towns = [0] * N town = 1 i = 0 while True: if towns[town-1] < 2: if towns[town-1] == 0: i += 1 towns[town-1] += 1 town = A[town-1] else: s = town break loop = towns....
[["-", 64, 196, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 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
176
#include <bits/stdc++.h> using namespace std; #define pi acos(-1) #define mod 1000000007 #define ll long long #define ull unsigned long long #define mem(a) memset(a, 0, sizeof(a)) #define cio ios::sync_with_stdio(false); ll s[200010]; ll q[200010]; int main() { ll n, k; cin >> n >> k; for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; #define pi acos(-1) #define mod 1000000007 #define ll long long #define ull unsigned long long #define mem(a) memset(a, 0, sizeof(a)) #define cio ios::sync_with_stdio(false); ll s[200010]; ll q[200010]; int main() { ll n, k; cin >> n >> k; for (int i = 1; i <= n; i++)...
[["+", 31, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
239
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; ++i) cin >> a[i]; for (auto &x : a) --x; set<ll> vs; vector<ll> vv; ll i = 0; vs.insert(i); while (true) { vv.push_back(i); i = a[i]; l...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; ++i) cin >> a[i]; for (auto &x : a) --x; set<ll> vs; vector<ll> vv; ll i = 0; vs.insert(i); while (true) { vv.push_back(i); i = a[i]; l...
[["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
224
n, k = map(int, input().split()) list_A = list(map(int, input().split())) list_MAP = [] set_MAP = set() x = 1 while True: list_MAP.append(x) set_MAP.add(x) x = list_A[x-1] if x in set_MAP: break q = len(list_MAP) - list_MAP.index(x) p = k - list_MAP.index(x) if p < 0: print(list_MAP[k-1])...
n, k = map(int, input().split()) list_A = list(map(int, input().split())) list_MAP = [] set_MAP = set() x = 1 while True: list_MAP.append(x) set_MAP.add(x) x = list_A[x-1] if x in set_MAP: break q = len(list_MAP) - list_MAP.index(x) p = k - list_MAP.index(x) if p < 0: print(list_MAP[k]) e...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
134
import sys n,k=map(int,input().split()) a=list(map(int,input().split())) visited=[0]*n town=0 Town=0 visited[0]=0 lst=[] if a[0]==1: print(1) sys.exit() for i in range(n): town=a[town]-1 if visited[town]!=0 or town==0: lst.append([town,visited[town],i+1]) break else: visited[town]=i+1 Lst=[] town=...
import sys n,k=map(int,input().split()) a=list(map(int,input().split())) visited=[0]*n town=0 Town=0 visited[0]=0 lst=[] if a[0]==1: print(1) sys.exit() for i in range(n): town=a[town]-1 if visited[town]!=0 or town==0: lst.append([town,visited[town],i+1]) break else: visited[town]=i+1 Lst=[] town=...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
308
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef string str; int main() { // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); ll t, n, m, k, i, a, b, j; cin >> n >> k; ll arr[n + 2]; for (i = 1; i < n + 1; i++) { cin >> arr[i]; } vector<ll> v; ll h[n...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef string str; int main() { // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); ll t, n, m, k, i, a, b, j; cin >> n >> k; ll arr[n + 2]; for (i = 1; i < n + 1; i++) { cin >> arr[i]; } vector<ll> v; ll h[n...
[["-", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13]]
1
278
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = ...
[["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 12, 69, 341, 342, 0, 69, 341, 342, 0, 73]]
1
330
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n,k = na() a = na() dp = [-1]*n dp[0] = 0 i = 1 now = 0 loop = -1 start = -1 while True: now = a...
import sys stdin = sys.stdin sys.setrecursionlimit(10**6) ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n,k = na() a = na() dp = [-1]*n dp[0] = 0 i = 1 now = 0 loop = -1 start = -1 while True: now = a...
[["+", 8, 196, 0, 1, 0, 662, 12, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 206, 0, 70], ["+", 8, 196, 0, 1, 0, 662, 12, 206, 0, 73]]
5
191
n,k = list(map(int, input().split())) a = list(map(int, input().split())) a.insert(0,0) start = 1 now = start c = 0 flag = [-1]*(n+1) while c <= k and flag[now] == -1: #print(now) flag[now] = c c+= 1 now = a[now] #print(c, now) if c == k: print(now) else: k-=c cc = c-flag[now] nokori = k...
n,k = list(map(int, input().split())) a = list(map(int, input().split())) a.insert(0,0) start = 1 now = start c = 0 flag = [-1]*(n+1) while c < k and flag[now] == -1: #print(now) flag[now] = c c+= 1 now = a[now] #print(c, now) if c == k: print(now) else: k-=c cc = c-flag[now] nokori = k ...
[["-", 0, 656, 0, 52, 15, 679, 31, 666, 667, 19], ["+", 0, 656, 0, 52, 15, 679, 31, 666, 667, 18]]
5
140
n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] def find_min_cycle(a): memo = {1: 0} idx = 0 cnt = 1 while a[idx] not in memo: memo[a[idx]] = cnt cnt += 1 idx = a[idx]-1 return memo[a[idx]], cnt-memo[a[idx]], memo offset, cycle_len, memo = f...
n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] def find_min_cycle(a): memo = {1: 0} idx = 0 cnt = 1 while a[idx] not in memo: memo[a[idx]] = cnt cnt += 1 idx = a[idx]-1 return memo[a[idx]], cnt-memo[a[idx]], memo offset, cycle_len, memo = f...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22]]
5
165
n,k= map(int,input().split()) A = [0] A += list(map(int,input().split())) B = [-1 for _ in range(n+1)] B[1] = 0 now =1 cnt = 0 cic = 0 for i in range(1,n+1): now = A[now] cnt +=1 if B[now] ==-1: B[now] = cnt else: cic = cnt - B[now] road = B[now] break if k <= road: ...
n,k= map(int,input().split()) A = [0] A += list(map(int,input().split())) B = [-1 for _ in range(n+1)] B[1] = 0 now =1 cnt = 0 cic = 0 for i in range(1,n+1): now = A[now] cnt +=1 if B[now] ==-1: B[now] = cnt else: cic = cnt - B[now] road = B[now] break if k <= road: ...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
158
N , K = map(int, input().split()) li = list(map(int, input().split())) if K < N: town = 0 for i in range(N): town = li[town]-1 print(town+1) else: li2 = [0for i in range(N)] count = 1 town = 0 while(1): if li2[town] != 0: num = count - li2[town] num2 =...
N , K = map(int, input().split()) li = list(map(int, input().split())) if K < N: town = 0 for i in range(K): town = li[town]-1 print(town+1) else: li2 = [0for i in range(N)] count = 1 town = 0 while(1): if li2[town] != 0: num = count - li2[town] num2 =...
[["-", 64, 196, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 7, 12, 652, 3, 4, 0, 22]]
5
164
#include <bits/stdc++.h> #define ll long long #define pb push_back #define c(P) cout << P << "\n" #define pii pair<ll, ll> #define mi map<ll, ll> #define mii map<pii, ll> #define F first #define S second #define sz(a) (ll)(a.size()) #define cr(P) \ cou...
#include <bits/stdc++.h> #define ll long long #define pb push_back #define c(P) cout << P << "\n" #define pii pair<ll, ll> #define mi map<ll, ll> #define mii map<pii, ll> #define F first #define S second #define sz(a) (ll)(a.size()) #define cr(P) \ cou...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
338
#include <bits/stdc++.h> using namespace std; typedef long long int ll; void solve() { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; ++i) { /* code */ cin >> a[i]; } vector<ll> s; ll t = n + 1; ll i = 1; ll l = 0; bool flag = true; set<ll> r; while (t--) { if (r.find(i) !...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; void solve() { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; ++i) { /* code */ cin >> a[i]; } vector<ll> s; ll t = n + 1; ll i = 1; ll l = 0; bool flag = true; set<ll> r; while (t--) { if (r.find(i) !...
[["+", 15, 339, 51, 16, 12, 2, 63, 23, 0, 22], ["+", 15, 339, 51, 16, 12, 2, 63, 23, 0, 25], ["+", 15, 339, 51, 16, 12, 2, 3, 4, 0, 24], ["-", 0, 57, 64, 9, 0, 57, 64, 1, 0, 35], ["+", 64, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 64, 9, 0, 57, 64, 9, 0, 93, 0, 94]]
1
268
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { ...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
1,771
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = int(a); i <= int(b); ++i) using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << "...
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = int(a); i <= int(b); ++i) using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << "...
[["-", 0, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
560
#include <bits/stdc++.h> using namespace std; int arr[200005], sequence[200005]; bool visited[200005]; long long n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; sequence[0] = 1; visited[0] = true; int i = 1, current = 1; while (i == 1 || visited[current - 1] == false) { ...
#include <bits/stdc++.h> using namespace std; int arr[200005], sequence[200005]; bool visited[200005]; long long n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; sequence[0] = 1; visited[0] = true; int i = 1, current = 1; while (i == 1 || visited[current - 1] == false) { ...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
222
N,K=map(int, input().split()) A=list(map(int, input().split())) check=[0]*(N) check[0]=1 D=[] C=[0] p=0 for i in range(N): pp=A[p]-1 if check[pp]==0: check[pp]=1 C.append(pp) p=pp else: roop=pp break rs=C.index(roop) if K<=rs-1: print(C[K]+1) else: K-=(rs-1) F=C[rs:] e=K%(len(F)) pri...
N,K=map(int, input().split()) A=list(map(int, input().split())) check=[0]*(N) check[0]=1 D=[] C=[0] p=0 for i in range(N): pp=A[p]-1 if check[pp]==0: check[pp]=1 C.append(pp) p=pp else: roop=pp break rs=C.index(roop) if K<=rs-1: print(C[K]+1) else: K-=(rs-1) F=C[rs:] e=K%(len(F)) pri...
[["-", 0, 652, 3, 4, 0, 657, 31, 206, 51, 22], ["+", 0, 652, 3, 4, 0, 657, 31, 206, 51, 22]]
5
166
n,k=map(int,input().split()) A=list(map(int,input().split())) tele=[0 for _ in range(n+1)] cnt=1 v=1 while True: if tele[v]!=0: break else: tele[v]=cnt cnt+=1 v=A[v-1] circle_in=tele[v] circle=[] for idx,t in enumerate(tele): if t<circle_in: continue else: ...
n,k=map(int,input().split()) A=list(map(int,input().split())) tele=[0 for _ in range(n+1)] cnt=1 v=1 while True: if tele[v]!=0: break else: tele[v]=cnt cnt+=1 v=A[v-1] circle_in=tele[v] circle=[] for idx,t in enumerate(tele): if t<circle_in: continue else: ...
[["+", 0, 662, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 12, 612]]
5
204
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << x << " = "(x) << endl; #define ll long long #define rep(i, x, y) for (ll i = x; i < y; i++) #define rel(i, x, y) for (int i = x - 1; i >= y; i--) #define all(x) x.begin(), x.end() int main() { cin.tie(nullptr); ios::sync_with_stdio(false); c...
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << x << " = "(x) << endl; #define ll long long #define rep(i, x, y) for (ll i = x; i < y; i++) #define rel(i, x, y) for (int i = x - 1; i >= y; i--) #define all(x) x.begin(), x.end() int main() { cin.tie(nullptr); ios::sync_with_stdio(false); c...
[["-", 75, 76, 0, 9, 0, 1, 0, 11, 12, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 13]]
1
333
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> typedef long long int ll; using namespace std; #define maxn 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f const int mm = 1e6; ll d[mm]; ll vis[mm]; ll vv[mm]; ll dd[mm]; ll ddd[...
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> typedef long long int ll; using namespace std; #define maxn 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f const int mm = 1e6; ll d[mm]; ll vis[mm]; ll vv[mm]; ll dd[mm]; ll ddd[...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
306
int1 = lambda s: int(s)-1 N, K = map(int, input().split()) A = list(map(int1, input().split())) X = [] visited = set() now = 0 while now not in visited: visited.add(now) X.append(now) now = A[now] if K < len(X): print(X[K]) else: s = X.index(now) print(X[s + ((K - s) % (len(X) - s))] + 1)
int1 = lambda s: int(s)-1 N, K = map(int, input().split()) A = list(map(int1, input().split())) X = [] visited = set() now = 0 while now not in visited: visited.add(now) X.append(now) now = A[now] if K < len(X): print(X[K] + 1) else: s = X.index(now) print(X[s + ((K - s) % (len(X) - s))] + 1)...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
131
N, K = map(int, input().split()) A = list(map(int, input().split())) visited = {1: 0} index = 0 last = 1 for i in range(K): t = A[last - 1] index += 1 if t in visited: z = K - i - 1 l = index - visited[t] print([k for k, v in visited.items() if v == visited[t] + (z % l)][0]) ...
N, K = map(int, input().split()) A = list(map(int, input().split())) visited = {1: 0} index = 0 last = 1 for i in range(K): t = A[last - 1] index += 1 if t in visited: z = K - i - 1 l = index - visited[t] print([k for k, v in visited.items() if v == visited[t] + (z % l)][0]) ...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 70], ["-", 0, 652, 3, 4, 0, 206, 206, 664, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 664, 28, 612], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22]]
5
139
N,K = map(int,input().split()) A = list(map(lambda x: int(x) - 1, input().split())) P = [-1] * N cur = 0 P[cur] = 0 route = [1] for step in range(K): cur = A[cur] route.append(cur + 1) if P[cur] >= 0: l_start = P[cur] l_end = step + 1 l_len = l_end - l_start break else: P[cur] = step + 1 e...
N,K = map(int,input().split()) A = list(map(lambda x: int(x) - 1, input().split())) P = [-1] * N cur = 0 P[cur] = 0 route = [1] for step in range(K): cur = A[cur] route.append(cur + 1) if P[cur] >= 0: l_start = P[cur] l_end = step + 1 l_len = l_end - l_start break else: P[cur] = step + 1 e...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
146
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int N; long long K; cin >> N >> K; int A[N]; rep(i, N) cin >> A[i]; // int m[N + 1]; rep(i, N) m[i + 1] = A[i]; pair<int, bool> visit[N + 1]; ...
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int N; long long K; cin >> N >> K; int A[N]; rep(i, N) cin >> A[i]; // int m[N + 1]; rep(i, N) m[i + 1] = A[i]; pair<int, bool> visit[N + 1]; ...
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
227
N,K = map(int,input().split()) A = [0] + list(map(int,input().split())) ans = 1 n = 1 check = 1 city = [-1 for i in range(N+1)] city[1] = 0 roop = 1 i = 0 while(check == 1): if i == K: check = 0 else: n = A[n] i = i + 1 if city[n] == -1: city[n] = i else: roop = i - city[n] + 1 ...
N,K = map(int,input().split()) A = [0] + list(map(int,input().split())) ans = 1 n = 1 check = 1 city = [-1 for i in range(N+1)] city[1] = 0 roop = 1 i = 0 while(check == 1): if i == K: check = 0 else: n = A[n] i = i + 1 if city[n] == -1: city[n] = i else: roop = i - city[n] ch...
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
158
#include <iostream> #include <set> #include <stack> #include <vector> using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a.at(i); --a.at(i); } vector<bool> seen(n); vector<int> hist; int v = 0; vector<int> x(n, -1); ...
#include <iostream> #include <set> #include <stack> #include <vector> using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a.at(i); --a.at(i); } vector<bool> seen(n); vector<int> hist; int v = 0; vector<int> x(n, -1); ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 12, 16, 31, 2, 3, 4, 0, 16, 17, 33], ["-", 12, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
1
245
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> firstpath; vector<long long> roop; long long N; long long K; ; cin >> N >> K; long long A[N], visited[N]; for (int i = 0; i < N; i++) { cin >> A[i]; A[i]--; visited[i] = 0; } long long now, roopstart; now = A[...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> firstpath; vector<long long> roop; long long N; long long K; ; cin >> N >> K; long long A[N], visited[N]; for (int i = 0; i < N; i++) { cin >> A[i]; A[i]--; visited[i] = 0; } long long now, roopstart; now = A[...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
290
N,K = map(int,input().split(" ")) A = list(map(int,input().split(" "))) A.insert(0,0) rireki = [1] counter = 1 now = 1 flag = [0 for _ in range(N + 1)] flag[1] = 1 while(flag[A[now]] == 0): counter += 1 rireki.append(A[now]) flag[A[now]] = counter now = A[now] if K < flag[A[now]]: print(rireki[K - 1...
N,K = map(int,input().split(" ")) A = list(map(int,input().split(" "))) A.insert(0,0) rireki = [1] counter = 1 now = 1 flag = [0 for _ in range(N + 1)] flag[1] = 1 while(flag[A[now]] == 0): counter += 1 rireki.append(A[now]) flag[A[now]] = counter now = A[now] if K < flag[A[now]]: print(rireki[K]) e...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
198
N, K = map(int, input().split()) A = list(map(int, (input().split()))) done = [0]*N now = 0 cnt = 1 while True: if done[now] != 0: start = done[now] - 1 cycle = cnt - start - 1 break else: done[now] = cnt now = A[now]-1 cnt += 1 if K>=start: K -= start K ...
N, K = map(int, input().split()) A = list(map(int, (input().split()))) done = [0]*N now = 0 cnt = 1 while True: if done[now] != 0: start = done[now] - 1 cycle = cnt - start - 1 break else: done[now] = cnt now = A[now]-1 cnt += 1 if K>=start: K -= start K ...
[["+", 36, 36, 0, 656, 0, 57, 75, 76, 0, 95], ["+", 36, 36, 0, 656, 0, 57, 75, 76, 0, 102], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 12, 612]]
5
127
import sys sys.setrecursionlimit(10**7) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, k = na() a = na() for i in range(n): a[i] -= 1 ct = [0 for i in range(n)] seen = [False] * n def dfs(v): ...
import sys sys.setrecursionlimit(10**7) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces n, k = na() a = na() for i in range(n): a[i] -= 1 ct = [0 for i in range(n)] seen = [False] * n def dfs(v): ...
[["-", 8, 196, 0, 57, 15, 666, 0, 206, 206, 22], ["+", 0, 57, 15, 666, 0, 657, 31, 206, 206, 22], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["-", 0, 656, 0, 14, 8, 196, 0, 57, 0, 121], ["+", 0, 14, 8, 196, 0, 57, 75, 665, 0, 683]]
5
218
def main(): from sys import stdin n,k = map(int,stdin.readline().rstrip().split()) As = list(map(int,stdin.readline().rstrip().split())) As = [0]+As g = set({1}) l = [0,1] now = 1 i = 0 while True: i+=1 now = As[now] if now in g: j = l.index(now) ...
def main(): from sys import stdin n,k = map(int,stdin.readline().rstrip().split()) As = list(map(int,stdin.readline().rstrip().split())) As = [0]+As g = set({1}) l = [0,1] now = 1 i = 0 while True: i+=1 now = As[now] if now in g: j = l.index(now) ...
[["-", 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]]
5
159
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define ok() puts(ok ? "Yes" : "No"); using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<bool> vb; typedef vector<vb> vvb; typedef set<int> s...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define ok() puts(ok ? "Yes" : "No"); using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<bool> vb; typedef vector<vb> vvb; typedef set<int> s...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
316
N, K= [int(i) for i in input().split()] An = [int(i) for i in input().split()] i = 0 checked = [0 for _ in range(N)] c = 0 while checked[i] == 0: c += 1 checked[i] = c i = An[i] - 1 if checked[i] >= K: i = 0 for k in range(mod_K): i = An[i] - 1 print(i + 1) else: period = c - checked[i] + 1 diff = ...
N, K= [int(i) for i in input().split()] An = [int(i) for i in input().split()] i = 0 checked = [0 for _ in range(N)] c = 0 while checked[i] == 0: c += 1 checked[i] = c i = An[i] - 1 if checked[i] >= K: i = 0 for k in range(K): i = An[i] - 1 print(i + 1) else: period = c - checked[i] + 1 diff = K - ...
[["-", 64, 196, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 7, 12, 652, 3, 4, 0, 22]]
5
163
// A.cpp #include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; } ll ...
// A.cpp #include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; } ll ...
[["-", 0, 2, 3, 4, 0, 16, 31, 69, 28, 22], ["-", 3, 4, 0, 16, 31, 69, 341, 342, 0, 70], ["-", 3, 4, 0, 16, 31, 69, 341, 342, 0, 73], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72]]
1
551
#include <bits/stdc++.h> using namespace std; int INF = 1e9 + 5; int main() { int n; long long k; cin >> n >> k; vector<int> a(n + 1), seen(n + 1, -1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int pos = 1, cycle = -1, move = 0; for (; move <= k; move++) { if (seen[pos] != -1) { cyc...
#include <bits/stdc++.h> using namespace std; int INF = 1e9 + 5; int main() { int n; long long k; cin >> n >> k; vector<int> a(n + 1), seen(n + 1, -1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int pos = 1, cycle = -1, move = 0; for (; move < k; move++) { if (seen[pos] != -1) { cycl...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
1
184
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FILL0(x) memset(x, 0, sizeof(x)) using namespace std; typedef long long ll; typedef pair<int, int> P; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> b...
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FILL0(x) memset(x, 0, sizeof(x)) using namespace std; typedef long long ll; typedef pair<int, int> P; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> b...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
329
#include <iostream> #include <sstream> #include <stdio.h> #define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <ctype.h> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef ...
#include <iostream> #include <sstream> #include <stdio.h> #define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <ctype.h> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef ...
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64...
1
344
def input_n gets.to_i # 単一整数 end def input_s gets.chomp # 文字列。chompを付けないと改行文字がついてくる end def input_a gets.split.map(&:to_i) # スペースで区切られた複数の整数 end def input_o(num) num.times.map { gets.to_i } # 縦に並んだ複数の整数。たまにある end def output_f(num) puts sprintf("%.12f", num) end n, k = input_a...
def input_n gets.to_i # 単一整数 end def input_s gets.chomp # 文字列。chompを付けないと改行文字がついてくる end def input_a gets.split.map(&:to_i) # スペースで区切られた複数の整数 end def input_o(num) num.times.map { gets.to_i } # 縦に並んだ複数の整数。たまにある end def output_f(num) puts sprintf("%.12f", num) end n, k = input_a...
[["-", 0, 493, 0, 652, 3, 4, 0, 742, 500, 22], ["-", 0, 493, 0, 652, 3, 4, 0, 742, 0, 70], ["-", 0, 493, 0, 652, 3, 4, 0, 742, 0, 73], ["+", 0, 493, 0, 652, 3, 4, 0, 738, 17, 72], ["+", 0, 493, 0, 652, 3, 4, 0, 738, 12, 612]]
4
158
N, K = list(map(int, input().split())) A = list(map(int, input().split())) if K == 1: print(A[0]) exit() if A[0] == 1: print(1) exit() # (cnt, k) visit_town = [(0, 0)]*N history = [0]*N visit_town[0] = (1, 0) history[0] = 1 visit = -1 for i in range(K): next_town = A[history[i]-1] if visit_t...
N, K = list(map(int, input().split())) A = list(map(int, input().split())) if K == 1: print(A[0]) exit() if A[0] == 1: print(1) exit() # (cnt, k) visit_town = [(0, 0)]*N history = [0]*N visit_town[0] = (1, 0) history[0] = 1 visit = -1 for i in range(K): next_town = A[history[i]-1] if visit_t...
[["+", 0, 1, 0, 662, 12, 660, 0, 657, 17, 72], ["+", 0, 1, 0, 662, 12, 660, 0, 657, 12, 612], ["+", 12, 657, 12, 23, 0, 657, 31, 657, 17, 72], ["+", 12, 657, 12, 23, 0, 657, 31, 657, 12, 612]]
5
223
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n), ct(n); for (ll i = 0; i < n; i++) { cin >> a[i]; a[i]--; ct[i] = 0; } ct[0] = 1; ll counter = 0; ll current = 0; for (ll i = 0; i < k; i++) { current = a[current];...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n), ct(n); for (ll i = 0; i < n; i++) { cin >> a[i]; a[i]--; ct[i] = 0; } ct[0] = 1; ll counter = 0; ll current = 0; for (ll i = 0; i < k; i++) { current = a[current];...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
266
N, K = map(int, input().split()) A = list(map(lambda x:int(x) - 1, input().split())) already = [False for i in range(N)] already[0] = True tel = [0] while True: tmp = A[tel[-1]] tel.append(tmp) if already[tmp]: tel.pop() break already[tmp] = True for i in range(len(tel))...
N, K = map(int, input().split()) A = list(map(lambda x:int(x) - 1, input().split())) already = [False for i in range(N)] already[0] = True tel = [0] while True: tmp = A[tel[-1]] tel.append(tmp) if already[tmp]: tel.pop() break already[tmp] = True for i in range(len(tel))...
[["+", 0, 652, 3, 4, 0, 657, 31, 206, 0, 73], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73]]
5
169
def main(): n, k = map(int, input().split()) A = list(map(int, input().split())) D = [0] * (n+1) now = 1 for i in range(1, k+1): tmp = A[now-1] if not D[tmp]: now = tmp D[now] += i else: mod = D[tmp] - 1 loop = i - D[tmp] ...
def main(): n, k = map(int, input().split()) A = list(map(int, input().split())) D = [0] * (n+1) now = 1 for i in range(1, k+1): tmp = A[now-1] if not D[tmp]: now = tmp D[now] += i else: pre = D[tmp] loop = i - D[tmp] ...
[["-", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612], ["-", 0, 657, 31, 657, 31, 23, 0, 657, 12, 22], ["+", 0, 657, 31, 657, 31, 23, 0, 657, 12, 22], ["-", 0, 41, 0, 652, 3, 4, 0, 657, 12, 2...
5
137
/* (1)for binary shift operator always use 'LL' 1LL<<63 */ #include <bits/stdc++.h> using namespace std; #define ll long long #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set_pair \ tre...
/* (1)for binary shift operator always use 'LL' 1LL<<63 */ #include <bits/stdc++.h> using namespace std; #define ll long long #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set_pair \ tre...
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 75, 76, 0, 1, 0, 35]]
1
267
#include <bits/stdc++.h> using namespace std; #define ll long long int ll N, K; vector<ll> A(200005); vector<ll> A2(200005, 0); vector<ll> check(200005, 0); ll amari, shuu; void loop() { ll shuuki = 1, now = 0, a; while (1) { ll next = A.at(now); if (check.at(next) == 1) { // cout<<"next"<<next<<e...
#include <bits/stdc++.h> using namespace std; #define ll long long int ll N, K; vector<ll> A(200005); vector<ll> A2(200005, 0); vector<ll> check(200005, 0); ll amari, shuu; void loop() { ll shuuki = 1, now = 0, a; while (1) { ll next = A.at(now); if (check.at(next) == 1) { // cout<<"next"<<next<<e...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
320
#include <bits/stdc++.h> using namespace std; #define int ll #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define sz(v) (int)((v).size()) #define fs first #define sd second typedef long long ll; typedef pair<int, int> pi; typedef pair<pi, int> ppi; typedef vector<int> vi; type...
#include <bits/stdc++.h> using namespace std; #define int ll #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define sz(v) (int)((v).size()) #define fs first #define sd second typedef long long ll; typedef pair<int, int> pi; typedef pair<pi, int> ppi; typedef vector<int> vi; type...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
580
// naveen mall #include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #...
// naveen mall #include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #...
[["-", 64, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 64, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
1
403
N,K=map(int,input().split()) A=list(map(int,input().split())) ischecked=[0]*N move=[] move1=[] now=0 count=0 count1=0 while 1: move.append(now+1) nex=A[now]-1 ischecked[now]=1 if ischecked[nex]==1: roop=nex+1 break now=nex for i in range(len(move))[::-1]: move1.append(move[i]) ...
N,K=map(int,input().split()) A=list(map(int,input().split())) ischecked=[0]*N move=[] move1=[] now=0 count=0 count1=0 while 1: move.append(now+1) nex=A[now]-1 ischecked[now]=1 if ischecked[nex]==1: roop=nex+1 break now=nex for i in range(len(move))[::-1]: move1.append(move[i]) ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20]]
5
189
from collections import defaultdict N,K=list(map(int,input().split())) a_list=list(map(int,input().split())) alr = defaultdict(int) alr[1] = 1 counter = 2 next = a_list[0] base_roop = 0 last_index = 1 while True: if alr[next] != 0: base_roop = counter-1 break else: alr[next] = counter ...
from collections import defaultdict N,K=list(map(int,input().split())) a_list=list(map(int,input().split())) alr = defaultdict(int) alr[1] = 1 counter = 2 next = a_list[0] base_roop = 0 last_index = 1 while True: if alr[next] != 0: base_roop = counter-1 break else: alr[next] = counter ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 19], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 18]]
5
235
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { int temp; cin >> temp; A[i] = temp - 1; } int T; int loop_pos = 0, pos = 0; if (N >= K) { for (int i = 0; i < K; i++) { pos = A[pos]; } ...
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { int temp; cin >> temp; A[i] = temp - 1; } int T; int loop_pos = 0, pos = 0; if (N >= K) { for (int i = 0; i < K; i++) { pos = A[pos]; } ...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
222
#include <bits/stdc++.h> using namespace std; #define int long long int int32_t main() { int n, k, i, t, c, l, num = 1, l1 = 0, r; cin >> n >> k; int a[n + 1]; vector<int> v; int vis[n + 1] = {0}; for (i = 1; i <= n; i++) { cin >> a[i]; } v.push_back(1); vis[1] = 1; c = 1; while (1) { t =...
#include <bits/stdc++.h> using namespace std; #define int long long int int32_t main() { int n, k, i, t, c, l, num = 1, l1 = 0, r; cin >> n >> k; int a[n + 1]; vector<int> v; int vis[n + 1] = {0}; for (i = 1; i <= n; i++) { cin >> a[i]; } v.push_back(1); vis[1] = 1; c = 1; while (1) { t =...
[["-", 0, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
244
#include <bits/stdc++.h> using namespace std; using lint = long long int; int main() { lint N, K; cin >> N >> K; vector<lint> A(N); for (auto &elem : A) cin >> elem; for (auto &elem : A) elem--; if (K <= N + N) { lint idx = 0; for (lint i = 0; i < K; i++) { idx = A[idx]; } c...
#include <bits/stdc++.h> using namespace std; using lint = long long int; int main() { lint N, K; cin >> N >> K; vector<lint> A(N); for (auto &elem : A) cin >> elem; for (auto &elem : A) elem--; if (K <= N + N) { lint idx = 0; for (lint i = 0; i < K; i++) { idx = A[idx]; } c...
[["-", 341, 342, 0, 16, 12, 2, 63, 118, 28, 22], ["+", 341, 342, 0, 16, 12, 2, 63, 118, 28, 22]]
1
236
#include <bits/stdc++.h> using namespace std; int main() { int p = 0, q = 0; int n = 0, k = 0; cin >> n >> k; vector<bool> a(n, false); vector<long long> b(n, 0); int count = k, genzaiti = 1; bool kikkake = false; for (int i = 0; i < n; i++) { cin >> b.at(i); } while (kikkake == false) { i...
#include <bits/stdc++.h> using namespace std; int main() { long long p = 0, q = 0; long long n = 0, k = 0; cin >> n >> k; vector<bool> a(n, false); vector<long long> b(n, 0); long long count = k, genzaiti = 1; bool kikkake = false; for (int i = 0; i < n; i++) { cin >> b.at(i); } while (kikkake...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
263
N, K = map(int, input().split()) A = list(map(int, input().split())) tele = [0] * N for i in range(N): tele[i] = A[i] - 1 now = 0 cnt = 0 exp = [False] * N period = 0 loop = False start = -1 while cnt < K: exp[now] = True now = tele[now] cnt += 1 if loop: period += 1 if now == start:...
N, K = map(int, input().split()) A = list(map(int, input().split())) tele = [0] * N for i in range(N): tele[i] = A[i] - 1 now = 0 cnt = 0 exp = [False] * N period = 0 loop = False start = -1 while cnt < K: exp[now] = True now = tele[now] cnt += 1 if loop: period += 1 if now == start:...
[["-", 0, 57, 64, 196, 0, 1, 0, 677, 17, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32]]
5
153
n, k = list(map(int, input().split())) al = list(map(int, input().split())) al = [a-1 for a in al] used = [0]*n first = [0]*n step = 0 used[0] = 1 now = 0 for i in range(k): step += 1 get = al[now] if used[get] == 0: first[get] = step used[get] = 1 now = get else: dif = s...
n, k = list(map(int, input().split())) al = list(map(int, input().split())) al = [a-1 for a in al] used = [0]*n first = [0]*n step = 0 used[0] = 1 now = 0 for i in range(k): step += 1 get = al[now] if used[get] == 0: first[get] = step used[get] = 1 now = get else: dif = s...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
165
n, k = map(int, input().split()) a = list(map(int, input().split())) b = 1 c = [-1]*n c[0] = 0 for i in range(n): b = a[b-1] if c[b-1] == -1: c[b-1] = i+1 else: d = i+1-c[b-1] e = c[b-1] break; b = 1 for i in range(e+(k-e)%d): b = a[b-1] print(b)
n, k = map(int, input().split()) a = list(map(int, input().split())) b = 1 c = [-1]*n c[0] = 0 for i in range(n): b = a[b-1] if c[b-1] == -1: c[b-1] = i+1 else: d = i+1-c[b-1] e = c[b-1] break; b = 1 for i in range(min(k, e+(k-e)%d)): b = a[b-1] print(b)
[["+", 0, 7, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 21], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
142
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<LD, LD> PDD; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define dbl(k, x) fixed << setprecision(k) << (x) t...
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<LD, LD> PDD; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define dbl(k, x) fixed << setprecision(k) << (x) t...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 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
385
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> num(n); for (int i = 0; i < n; i++) { ...
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> num(n); for (int i = 0; i < n; i++) { ...
[["-", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13]]
1
316
#include <bits/stdc++.h> using namespace std; #define endl '\n' const int nax = 2 * 1e5 + 5; int to[nax]; bool vis[nax]; int order[nax]; int cycleSize; int beginCycle; long long n, k; void solve(int u, int o) { while (to[u]) { if (order[u]) { cycleSize = o - order[u]; beginCycle = u; break; ...
#include <bits/stdc++.h> using namespace std; #define endl '\n' const int nax = 2 * 1e5 + 5; int to[nax]; bool vis[nax]; int order[nax]; long long cycleSize; int beginCycle; long long n, k; void solve(int u, int o) { while (to[u]) { if (order[u]) { cycleSize = o - order[u]; beginCycle = u; b...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 0, 30, 0, 43, 39, 86, 0, 96], ["+", 64, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 64, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
1
238
/** * “Experience is the name everyone gives to their mistakes.” – Oscar Wilde * * author : prodipdatta7 * created : Sunday 10-May, 2020 06:15:31 PM **/ //#include <bits/stdc++.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cs...
/** * “Experience is the name everyone gives to their mistakes.” – Oscar Wilde * * author : prodipdatta7 * created : Sunday 10-May, 2020 06:15:31 PM **/ //#include <bits/stdc++.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cs...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
1,180
#author: raghav_0901 from math import * mod = (10**9) + 7 def _in(): return [int(x) - 1 for x in input().split(' ')] def main(): n, k = [int(x) for x in input().split(' ')] arr, dp = _in(), [0, ] vis = [False] * (n) vis[0], nxt = True, arr[0] while(not vis[nxt] and len(dp) < k): dp....
#author: raghav_0901 from math import * mod = (10**9) + 7 def _in(): return [int(x) - 1 for x in input().split(' ')] def main(): n, k = [int(x) for x in input().split(' ')] arr, dp = _in(), [0, ] vis = [False] * (n) vis[0], nxt = True, arr[0] while(not vis[nxt] and len(dp) <= k): dp...
[["-", 0, 52, 15, 23, 0, 679, 12, 666, 667, 18], ["+", 0, 52, 15, 23, 0, 679, 12, 666, 667, 19], ["+", 0, 57, 15, 23, 0, 666, 0, 657, 17, 72], ["+", 0, 57, 15, 23, 0, 666, 0, 657, 12, 612]]
5
216
#include <bits/stdc++.h> using namespace std; #define endl '\n' int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; int a[n]; vector<int> cycle; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } set<int> used; int p = 0; while (!used.count(p)) {...
#include <bits/stdc++.h> using namespace std; #define endl '\n' int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; int a[n]; vector<int> cycle; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } set<int> used; int p = 0; while (!used.count(p)) {...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
229
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (n); i++) #define irep(i, n) for (int64_t i = 0; i <= (n...
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (n); i++) #define irep(i, n) for (int64_t i = 0; i <= (n...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 12, 69, 341, 342, 0, 73]]
1
265
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define repr(i, n) for (int i = (int)n - 1; i >= 0; --i) #define ALL(a) (a).begin(), (a).end() using ll = long long; // using Graph = vector<vector<int>>; const ll...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define repr(i, n) for (int i = (int)n - 1; i >= 0; --i) #define ALL(a) (a).begin(), (a).end() using ll = long long; // using Graph = vector<vector<int>>; const ll...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
321
n,k=map(int,input().split()) a=[0]*n a=list(map(int,input().split())) List=[0]*n pattern=[1] now=0 nex=0 List[0]=1 end_flag=0 while end_flag==0: nex=a[now] if (List[nex-1]==1): target1=nex end_flag=1 break else: List[nex-1]+=1 pattern.append(nex) now=nex-1 ...
n,k=map(int,input().split()) a=[0]*n a=list(map(int,input().split())) List=[0]*n pattern=[1] now=0 nex=0 List[0]=1 end_flag=0 while end_flag==0: nex=a[now] if (List[nex-1]==1): target1=nex end_flag=1 break else: List[nex-1]+=1 pattern.append(nex) now=nex-1 ...
[["+", 0, 57, 15, 23, 0, 666, 0, 657, 17, 33], ["+", 0, 57, 15, 23, 0, 666, 0, 657, 12, 612]]
5
174
def resolve(): n, g = map(int, input().split()) a = list(map(int, input().split())) ar = [-1] * n k = 0 now = 0 for i in range(n+1): if ar[now] == -1: ar[now] = k now = a[now]-1 k += 1 else: start = ar[now] startnode = n...
def resolve(): n, g = map(int, input().split()) a = list(map(int, input().split())) ar = [-1] * n k = 0 now = 0 for i in range(n+1): if ar[now] == -1: ar[now] = k now = a[now]-1 k += 1 else: start = ar[now] startnode = n...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22]]
5
174