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
n,k=map(int,input().split()) A=[0]+list(map(int,input().split())) color=["white" for _ in range(n+1)] DP,index=[],1 while 1: if color[index]=="white":color[index]="gray" elif color[index]=="gray":color[index]="black" DP.append(A[index]) index=A[index] if color[index]=="black":break repeat=[] for ...
n,k=map(int,input().split()) A=[0]+list(map(int,input().split())) color=["white" for _ in range(n+1)] DP,index=[],1 while 1: if color[index]=="white":color[index]="gray" elif color[index]=="gray":color[index]="black" DP.append(A[index]) index=A[index] if color[index]=="black":break repeat=[] for ...
[["+", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["+", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
229
n,k=map(int,input().split()) A=list(map(int,input().split())) time=0 color=["white" for _ in range(n+1)] D=[-1 for _ in range(n+1)] C,s=[],A[0] point=0 while 1: if color[s]=="white": color[s]="gray" C.append(s) D[s]=time time +=1 s=A[s-1] else: point=D[s] ...
n,k=map(int,input().split()) A=list(map(int,input().split())) time=0 color=["white" for _ in range(n+1)] D=[-1 for _ in range(n+1)] C,s=[],A[0] point=0 while 1: if color[s]=="white": color[s]="gray" C.append(s) D[s]=time time +=1 s=A[s-1] else: point=D[s] ...
[["-", 64, 196, 0, 1, 0, 677, 12, 657, 17, 72], ["-", 64, 196, 0, 1, 0, 677, 12, 657, 12, 612], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 0, 206, 206, 657, 12, 652, 3, 4, 0, 22], ["+", 206, 657, 31, 657, 12, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 206, 206, 657, 17, 3...
5
177
n,k=map(int,input().split()) A=list(map(int,input().split())) time=0 color=["white" for _ in range(n+1)] D=[-1 for _ in range(n+1)] C,s=[],A[0] point=0 while 1: if color[s]=="white": color[s]="gray" C.append(s) D[s]=time time +=1 s=A[s-1] else: point=D[s] ...
n,k=map(int,input().split()) A=list(map(int,input().split())) time=0 color=["white" for _ in range(n+1)] D=[-1 for _ in range(n+1)] C,s=[],A[0] point=0 while 1: if color[s]=="white": color[s]="gray" C.append(s) D[s]=time time +=1 s=A[s-1] else: point=D[s] ...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["-", 0, 206, 206, 657, 12, 652, 3, 4, 0, 22], ["+", 0, 206, 206, 657, 12, 652, 3, 4, 0, 22]]
5
177
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <...
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <...
[["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 13]]
1
600
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline sys.setrecursionlimit(500*500) import itertools from collections import Counter,deque def main(): n,k = map(int, input().split()) a = list(map(int, input().split())) c = [] mark = [-1]*n pos,l = 0,0 while ...
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline sys.setrecursionlimit(500*500) import itertools from collections import Counter,deque def main(): n,k = map(int, input().split()) a = list(map(int, input().split())) c = [] mark = [-1]*n pos,l = 0,0 while ...
[["-", 206, 657, 12, 657, 12, 23, 0, 657, 12, 612], ["+", 206, 657, 12, 657, 12, 23, 0, 657, 12, 22]]
5
186
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collection...
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collection...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47]]
5
242
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #includ...
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #includ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
1,254
from collections import Counter n, k = map(int, input().split()) A = list(map(int, input().split())) C = Counter([]) X, Y = [], [] m = 0 for _ in range(n): a = A[m]-1 C[m] += 1 X.append(m) if C[a] != 0: Y = X[X.index(a):] X = X[:X.index(a)] break m = a # print(X,Y) x=len(X) y...
from collections import Counter n, k = map(int, input().split()) A = list(map(int, input().split())) C = Counter([]) X, Y = [], [] m = 0 for _ in range(n): a = A[m]-1 C[m] += 1 X.append(m) if C[a] != 0: Y = X[X.index(a):] X = X[:X.index(a)] break m = a # print(X,Y) x = len(X)...
[["+", 0, 656, 0, 57, 15, 666, 0, 657, 17, 33], ["+", 0, 656, 0, 57, 15, 666, 0, 657, 12, 612]]
5
169
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] d = [] d_set = set() s = 1 for _ in range(N): if s in d_set: if K < len(d): print(d[K]) idx = d.index(s) K -= idx d = d[idx:] ...
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] d = [] d_set = set() s = 1 for _ in range(N): if s in d_set: if K < len(d): return print(d[K]) idx = d.index(s) K -= idx d = d[idx:] ...
[["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
5
146
N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) visited = [0] * (N + 1) route = [0] * (N + 1) next_ = 1 count = 0 for i in range(N + 1): if visited[next_] != 0: x = visited[next_] count = (K - (x - 1)) % (i + 1 - x) + x print(route[count]) exit() visi...
N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) visited = [0] * (N + 1) route = [0] * (N + 1) next_ = 1 count = 0 for i in range(K + 1): if visited[next_] != 0: x = visited[next_] count = (K - (x - 1)) % (i + 1 - x) + x print(route[count]) exit() visi...
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22]]
5
151
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_tuple(H): ''' H is number of rows ''' ret = [] for _ in range(H): ret.append(tuple...
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_tuple(H): ''' H is number of rows ''' ret = [] for _ in range(H): ret.append(tuple...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
399
#include <stdio.h> int main() { int i, N, A[200001]; long long K; scanf("%d %lld", &N, &K); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); int j, flag[200001] = {}; flag[1] = 1; for (i = 2, j = 1; flag[A[j]] == 0; i++, j = A[j]) flag[A[j]] = i; if ((long long)i - 1 > K) { for (j = 1; flag...
#include <stdio.h> int main() { int i, N, A[200001]; long long K; scanf("%d %lld", &N, &K); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); int j, flag[200001] = {}; flag[1] = 1; for (i = 2, j = 1; flag[A[j]] == 0; i++, j = A[j]) flag[A[j]] = i; if ((long long)i - 1 > K) { for (j = 1; flag...
[["-", 0, 16, 31, 16, 12, 69, 71, 69, 71, 22], ["+", 0, 16, 31, 16, 12, 69, 71, 69, 71, 22]]
0
251
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, i, k, n, c, cp; cin >> N >> K; vector<int> A(N); vector<int> r; vector<int> odr(N + 1, -1); for (auto &x : A) cin >> x; n = 1; while (odr[n] == -1) { odr[n] = r.size(); r.push_back(n); n = A[n - 1]; } cp = od...
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, i, k, n, c, cp; cin >> N >> K; vector<int> A(N); vector<int> r; vector<int> odr(N + 1, -1); for (auto &x : A) cin >> x; n = 1; while (odr[n] == -1) { odr[n] = r.size(); r.push_back(n); n = A[n - 1]; } cp = od...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 0, 57, 75, 76, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 12, 22]]
1
172
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<int> a(n); for (int j = 0; j < n; j++) { cin >> a[j]; } vector<int> s; vector<int> ord(n + 1, -1); int v = 1, c = 1, l = 0; while (ord[v] == -1) { ord[v] = s.size(); s.push_back(v); v = a...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<int> a(n); for (int j = 0; j < n; j++) { cin >> a[j]; } vector<int> s; vector<int> ord(n + 1, -1); int v = 1, c = 1, l = 0; while (ord[v] == -1) { ord[v] = s.size(); s.push_back(v); v = a...
[["+", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
179
#include <cctype> #include <cmath> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <tuple> #include <vector> #define N 10 using namespace std; int main(int argc, char cons...
#include <cctype> #include <cmath> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <bitset> #include <queue> #include <stack> #include <tuple> #include <vector> #define N 10 using namespace std; int main(int argc, char cons...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
237
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) \ { \ for (auto i : x) { ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) \ { \ for (auto i : x) { ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
224
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 200020; signed main() { int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> visited(N, 0); vector<int> path; path.push_back(1); int pos = 1; int cnt = 1; ...
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 200020; signed main() { int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> visited(N, 0); vector<int> path; path.push_back(1); int pos = 1; int cnt = 1; ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13]]
1
223
#include <bits/stdc++.h> typedef long long ll; const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f; const int N = 2e5 + 5; using namespace std; vector<ll> v; int boom[N]; int a[N]; int main() { ll n, k; cin >> n >> k; k++; for (int i = 1; i <= n; i++) cin >> a[i]; v.push_back(1); boom[1] = 1; int i = 1;...
#include <bits/stdc++.h> typedef long long ll; const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f; const int N = 2e5 + 5; using namespace std; vector<ll> v; int boom[N]; int a[N]; int main() { ll n, k; cin >> n >> k; k++; for (int i = 1; i <= n; i++) cin >> a[i]; v.push_back(1); boom[1] = 1; int i = 1;...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33]]
1
267
#include <bits/stdc++.h> #include <iostream> typedef long long ll; #define rep(i, a, b) for (ll i = a; i <= b; i++) #define per(i, a, b) for (ll i = a; i >= b; i--) using namespace std; typedef vector<int> vi; typedef vector<vector<int>> vvi; int main() { // ifstream cin("input.txt"); ll n, k, A; cin >> n >> k; ...
#include <bits/stdc++.h> #include <iostream> typedef long long ll; #define rep(i, a, b) for (ll i = a; i <= b; i++) #define per(i, a, b) for (ll i = a; i >= b; i--) using namespace std; typedef vector<int> vi; typedef vector<vector<int>> vvi; int main() { // ifstream cin("input.txt"); ll n, k, A; cin >> n >> k; ...
[["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
231
#include <bits/stdc++.h> #define PI 3.14159265359 #define rep(i, a, n) for (int i = a; i < (int)n; ++i) #define SZ(x) ((int)(x).size()) // size() unsigned -> int #define descSort(a) sort(a.begin(), a.end(), std::greater<int>()) using namespace std; typedef long long ll; const ll INF = 1e9 + 7; int main(void) { ll ...
#include <bits/stdc++.h> #define PI 3.14159265359 #define rep(i, a, n) for (int i = a; i < (int)n; ++i) #define SZ(x) ((int)(x).size()) // size() unsigned -> int #define descSort(a) sort(a.begin(), a.end(), std::greater<int>()) using namespace std; typedef long long ll; const ll INF = 1e9 + 7; int main(void) { ll ...
[["-", 64, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 64, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
1
212
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define vi vector<int> #define vll vector<ll> #define vvll vector<vll> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vb vector<bool> #define pii pair<int, int> #define vpli vector<pair<long long, int>> #d...
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define vi vector<int> #define vll vector<ll> #define vvll vector<vll> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vb vector<bool> #define pii pair<int, int> #define vpli vector<pair<long long, int>> #d...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
387
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; const int N = 2e5 + 5; ll a[N], step[N]; int main() { ll n, k; scanf("%lld%lld", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), step[i] = -1; ll t = 1, s = 0, r; while (1) { // printf("t = %lld s = %lld\n",t...
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; const int N = 2e5 + 5; ll a[N], step[N]; int main() { ll n, k; scanf("%lld%lld", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), step[i] = -1; ll t = 1, s = 0, r; while (1) { // printf("t = %lld s = %lld\n",t...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
252
n,k = map(int,input().split()) a = list(map(int,input().split())) for i in range(n): a[i] -= 1 visited = [-1] * n now = 0 for i in range(k+1): if visited[now] != -1: #訪れたことがあるか loop = i - visited[now] #ループの大きさ k = (k-(i-loop)) % loop for _ in range(k): now...
n,k = map(int,input().split()) a = list(map(int,input().split())) for i in range(n): a[i] -= 1 visited = [-1] * n now = 0 for i in range(k): if visited[now] != -1:#訪れたことがあるか loop = i - visited[now] #ループの大きさ k = (k-(i-loop)) % loop for _ in range(k): now = a[...
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
133
import sys input = sys.stdin.readline def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) B = [1] a = 1 check = [0] * len(A) while True: a = A[a - 1] if check[a - 1] == 1: x = B.index(a) roop = B[x:] print(roop[(K ...
import sys input = sys.stdin.readline def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) B = [1] a = 1 check = [0] * len(A) while True: a = A[a - 1] if check[a - 1] == 1: x = B.index(a) roop = B[x:] print(roop[(K ...
[["+", 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
161
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb pu...
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define pb pu...
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
256
n, k = map(int, input().split()) lst = [int(i) for i in input().split()] tele_lst = [] town_set = set() town = 1 while True: if town not in town_set: tele_lst.append(town) town_set.add(town) else: break town = lst[town - 1] ind = tele_lst.index(town) length = len(town_set) circle = length - ind #prin...
n, k = map(int, input().split()) lst = [int(i) for i in input().split()] tele_lst = [] town_set = set() town = 1 while True: if town not in town_set: tele_lst.append(town) town_set.add(town) else: break town = lst[town - 1] ind = tele_lst.index(town) length = len(town_set) circle = length - ind #prin...
[["-", 64, 196, 0, 1, 0, 662, 12, 206, 51, 22], ["+", 64, 196, 0, 1, 0, 662, 12, 206, 51, 22]]
5
135
# カウントと踏破フラグをもっておくと二度目の踏破でループの長さが分かりそう n, k = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) count_arr = [0] * n count = 0 now = 0 loop_length = -1 while True: if count == k: print(a[now] + 1) exit() if count_arr[now] != 0: loop_length = count - count_arr...
# カウントと踏破フラグをもっておくと二度目の踏破でループの長さが分かりそう n, k = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) count_arr = [0] * n count = 0 now = 0 loop_length = -1 while True: if count == k: print(now + 1) exit() if count_arr[now] != 0: loop_length = count - count_arr[n...
[["-", 0, 652, 3, 4, 0, 657, 31, 206, 51, 22], ["-", 0, 652, 3, 4, 0, 657, 31, 206, 0, 70], ["-", 0, 652, 3, 4, 0, 657, 31, 206, 0, 73]]
5
168
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define rep(i...
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define rep(i...
[["-", 31, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 12, 13], ["-", 49, 50, 51, 16, 12, 23, 0, 16, 17, 72], ["-", 49, 50, 51, 16, 12, 23, 0, 16, 12, 13]]
1
406
f=lambda:map(int,input().split()) n,k=f() a=list(f()) lv=[-1]*n lv[0]=0 p=0 for i in range(n): t=a[p]-1 if lv[t]>=0: l,r=lv[t],i+1 break lv[t]=i+1 p=t print(lv.index(l+(k-l)%(r-l))+1)
f=lambda:map(int,input().split()) n,k=f() a=list(f()) lv=[-1]*n lv[0]=0 p=0 for i in range(n): t=a[p]-1 if lv[t]>=0: l,r=lv[t],i+1 break lv[t]=i+1 p=t print(lv.index(l+(k-l)%(r-l) if k>l else k)+1)
[["+", 0, 657, 31, 652, 3, 4, 0, 41, 0, 121], ["+", 31, 652, 3, 4, 0, 41, 0, 666, 0, 22], ["+", 31, 652, 3, 4, 0, 41, 0, 666, 667, 47], ["+", 0, 657, 31, 652, 3, 4, 0, 41, 0, 95], ["+", 0, 657, 31, 652, 3, 4, 0, 41, 0, 22]]
5
119
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using namespace std; int main() { int n; ll k; cin >> n >> k; vector<int> as(n); rep(i, n) { cin >> as[i]; } vector<int> s; vector<int> ord(n + 1, -1); int c = 1, l = 0; int v = 1; while (ord[v] !=...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using namespace std; int main() { int n; ll k; cin >> n >> k; vector<int> as(n); rep(i, n) { cin >> as[i]; } vector<int> s; vector<int> ord(n + 1, -1); int c = 1, l = 0; int v = 1; while (ord[v] ==...
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60]]
1
195
n, k = map(int,input().split()) f = [int(x)-1 for x in input().split()] def tortoise_and_hare(s,f): tortoise = f[s] hare = f[f[s]] while tortoise != hare: tortoise = f[tortoise] hare = f[f[hare]] rho = 0 tortoise = s while tortoise != hare: tortoise = f[tortoise] ...
n, k = map(int,input().split()) f = [int(x)-1 for x in input().split()] def tortoise_and_hare(s,f): tortoise = f[s] hare = f[f[s]] while tortoise != hare: tortoise = f[tortoise] hare = f[f[hare]] rho = 0 tortoise = s while tortoise != hare: tortoise = f[tortoise] ...
[["-", 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
218
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #include <limits.h> using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <cl...
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #include <limits.h> using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <cl...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
448
from collections import Counter N, K = map(int,input().split()) tele = list(map(int, input().split())) #A1から順にワープした時の経由順 now = 0 goal,loop,visit = [],[],[0]*N while visit[now]!=2: if visit[now]==0: goal.append(now) else: loop.append(now) visit[now] += 1 now = tele[now]-1 if len(goal)>K: print...
from collections import Counter N, K = map(int,input().split()) tele = list(map(int, input().split())) #A1から順にワープした時の経由順 now = 0 goal,loop,visit = [],[],[0]*N while visit[now]!=2: if visit[now]==0: goal.append(now) else: loop.append(now) visit[now] += 1 now = tele[now]-1 if len(goal)>K: print...
[["+", 36, 36, 0, 656, 0, 57, 75, 76, 0, 95], ["+", 36, 36, 0, 656, 0, 57, 75, 76, 0, 102]]
5
148
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, ...
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, ...
[["-", 0, 14, 8, 9, 0, 1, 0, 27, 28, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 27, 17, 68], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
680
#include <bits/stdc++.h> #define rep0(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<string, int, int> TU; typedef tuple<int, int, int> TI; int main() { ll n, m; cin >> n >> m; ll input[n + 1...
#include <bits/stdc++.h> #define rep0(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<string, int, int> TU; typedef tuple<int, int, int> TI; int main() { ll n, m; cin >> n >> m; ll input[n + 1...
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 47]]
1
236
N, K = map(int, input().split()) A = list(map(lambda x: x - 1, map(int, input().split()))) print(A) current = 0 memo = { 0: 0 } for i in range(1, K + 1): current = A[current] if current in memo: # loop length length = i - memo[current] tmp = (K - memo[current]) % length # pri...
N, K = map(int, input().split()) A = list(map(lambda x: x - 1, map(int, input().split()))) current = 0 memo = { 0: 0 } for i in range(1, K + 1): current = A[current] if current in memo: # loop length length = i - memo[current] tmp = (K - memo[current]) % length for j in range...
[["-", 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
131
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll t; t = 1; // cin t; while (t--) { ll n, k; cin >> n >> k; vector<int> temp; temp.push_back(1); temp.push_back(1); ll a[n + 1]; int visited[n + 1]; for (int i = 1; i <= n; i++) { cin >> ...
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll t; t = 1; // cin t; while (t--) { ll n, k; cin >> n >> k; vector<int> temp; temp.push_back(1); temp.push_back(1); ll a[n + 1]; int visited[n + 1]; for (int i = 1; i <= n; i++) { cin >> ...
[["+", 31, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
229
#include <cmath> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { ll N; ll K; cin >> N; cin >> K; ll town[N + 1]; ll point[N + 1]; ll num = 0; for (ll i = 1; i < N + 1; ++i) { cin >> town[i]; } fo...
#include <cmath> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { ll N; ll K; cin >> N; cin >> K; ll town[N + 1]; ll point[N + 1]; ll num = 0; for (ll i = 1; i < N + 1; ++i) { cin >> town[i]; } fo...
[["+", 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, 73]]
1
292
N,K = map(int,input().split()) cc = list(map(int,input().split())) memo = [] aa = ['.']*N a = 1 while aa[a-1] == '.': memo.append(a) aa[a-1] = 'v' a = cc[a-1] if len(memo)>K: print(aa[K]) else: b = memo.index(a) m = len(memo)-b mm = (K-b) % m del memo[:b] print(memo[mm])
N,K = map(int,input().split()) cc = list(map(int,input().split())) memo = [] aa = ['.']*N a = 1 while aa[a-1] == '.': memo.append(a) aa[a-1] = 'v' a = cc[a-1] if len(memo)>K: print(memo[K]) else: b = memo.index(a) m = len(memo)-b mm = (K-b) % m del memo[:b] print(memo[mm])
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22]]
5
140
n, k = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) ls = [-1] * n now = 0 cnt = 0 path = [] while 1: if ls[now] != -1: b = ls[now] break ls[now] = cnt path.append(now) now = a[now] cnt += 1 loop = path[b:] if k <= b: print(path[k]) else: pri...
n, k = map(int, input().split()) a = list(map(lambda x: int(x) - 1, input().split())) ls = [-1] * n now = 0 cnt = 0 path = [] while 1: if ls[now] != -1: b = ls[now] break ls[now] = cnt path.append(now) now = a[now] cnt += 1 loop = path[b:] if k <= b: print(path[k] + 1) else: ...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
138
#include <bits/stdc++.h> using namespace std; #define pi acos(-1) #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(); \ cout.tie(...
#include <bits/stdc++.h> using namespace std; #define pi acos(-1) #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(); \ cout.tie(...
[["-", 51, 16, 12, 16, 31, 2, 63, 118, 28, 22], ["+", 51, 16, 12, 16, 31, 2, 63, 118, 28, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
1
309
n,k = map(int,input().split()) alist = list(map(int,input().split())) memo = [] p = 1 vis = ['.']*n while vis[p-1] == '.': memo.append(p) vis[p-1] = 'v' p = alist[p-1] loop = memo.index(p) if k < len(alist): print(memo[k]) else: print(memo[loop+(k-loop)%(len(memo)-loop)])
n,k = map(int,input().split()) alist = list(map(int,input().split())) memo = [] p = 1 vis = ['.']*n while vis[p-1] == '.': memo.append(p) vis[p-1] = 'v' p = alist[p-1] loop = memo.index(p) if k < len(memo): print(memo[k]) else: print(memo[loop+(k-loop)%(len(memo)-loop)])
[["-", 0, 57, 15, 666, 0, 652, 3, 4, 0, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 22]]
5
132
N,K = map(int, input().split()) A = list(map(int, input().split())) move = 1 l = [1] flag = [False]*(N+1) flag[1] = True for i in range(N): move = A[move-1] if flag[move]: break flag[move] = True l.append(move) ind = l.index(move) rest = (K-ind) % (len(l) - ind) + ind print(l[rest])
N,K = map(int, input().split()) A = list(map(int, input().split())) move = 1 l = [1] flag = [False]*(N+1) flag[1] = True for i in range(K): move = A[move-1] if flag[move]: break flag[move] = True l.append(move) ind = l.index(move) rest = (K-ind) % (len(l) - ind) + ind print(l[rest])
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22]]
5
126
#include <bits/stdc++.h> //#include <atcoder/all> #define INF 1e9 #define rep(i, n) for (long long i = 0; (i) < (long long)(n); i++) #define REP(i, a, b) \ for (long long i = (long long)(a); (i) <= (long long)(b); i++) #define VEC(type, c, n) ...
#include <bits/stdc++.h> //#include <atcoder/all> #define INF 1e9 #define rep(i, n) for (long long i = 0; (i) < (long long)(n); i++) #define REP(i, a, b) \ for (long long i = (long long)(a); (i) <= (long long)(b); i++) #define VEC(type, c, n) ...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
281
#入力:N,M(int:整数) def input2(): return map(int,input().split()) #入力:[n1,n2,...nk](int:整数配列) def input_array(): return list(map(int,input().split())) n,k=input2() A=input_array() # ある地点から循環に陥る judge=[True]*n tmps=[1] #循環手前 count=0 #参照地点 for i in range(2*(10**5)+1): if judge[count]==True: judge[count]=False co...
#入力:N,M(int:整数) def input2(): return map(int,input().split()) #入力:[n1,n2,...nk](int:整数配列) def input_array(): return list(map(int,input().split())) n,k=input2() A=input_array() # ある地点から循環に陥る judge=[True]*n tmps=[1] #循環手前 count=0 #参照地点 for i in range(2*(10**5)+1): if judge[count]==True: judge[count]=False co...
[["+", 0, 1, 0, 662, 12, 652, 63, 319, 0, 131], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
168
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a.at(i); } ll c, l; vector<ll> s; vector<ll> ord(n + 1, -1); ll v = 0; while (ord[v] == -1) { ord[v] = s....
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a.at(i); } ll c, l; vector<ll> s; vector<ll> ord(n + 1, -1); ll v = 0; while (ord[v] == -1) { ord[v] = s....
[["-", 12, 16, 31, 2, 3, 4, 0, 16, 17, 33], ["-", 12, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
1
194
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #defin...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #defin...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
728
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define...
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
308
n,k=map(int,input().split()) a=list(map(int,input().split())) data=[0]*(n+1) data[1]=1 ans=[1] res=0 for i in range(n): p=a[res] if data[p]==0: data[p]=1 ans.append(p) res=p-1 else: res=ans.index(p) break if len(ans)>=k: print(ans[k]) else: m=len(ans)-res k-=res d=k%m print(ans[res+d...
n,k=map(int,input().split()) a=list(map(int,input().split())) data=[0]*(n+1) data[1]=1 ans=[1] res=0 for i in range(n): p=a[res] if data[p]==0: data[p]=1 ans.append(p) res=p-1 else: res=ans.index(p) break if len(ans)>k: print(ans[k]) else: m=len(ans)-res k-=res d=k%m print(ans[res+d]...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47]]
5
150
#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>; #define chmax(x, y) x = max(x, y); #define chmin(x, y) x = min(x, y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { ...
#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>; #define chmax(x, y) x = max(x, y); #define chmin(x, y) x = min(x, y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["-", 12, 69, 341, 342, 0, 16, 31, 16, 17, 33], ["-", 12, 69, 341, 342, 0, 16, 31, 16, 12, 13]]
1
260
#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>; #define chmax(x, y) x = max(x, y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { int n; ll k; cin >> n >> k; v...
#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>; #define chmax(x, y) x = max(x, y); const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, -1, 0, 1}; const int INF = 1001001001; int main() { int n; ll k; cin >> n >> k; v...
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60]]
1
248
n,k=map(int,input().split()) a=[int(i) for i in input().split()] d=[0] w=set([0]) x=0 for i in range(n): if a[x]-1 not in w: d.append(a[x]-1) w.add(a[x]-1) x=a[x]-1 else: f=a[x]-1 break #print(d) if k<len(d): print(d[k]) else: x=k-len(d) y=d.index(f) z=le...
n,k=map(int,input().split()) a=[int(i) for i in input().split()] d=[0] w=set([0]) x=0 for i in range(n): if a[x]-1 not in w: d.append(a[x]-1) w.add(a[x]-1) x=a[x]-1 else: f=a[x]-1 break #print(d) if k<len(d): print(d[k]+1) else: x=k-len(d) y=d.index(f) z=...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
167
#!/usr/bin/env python3 import numpy as np # def input(): # return sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) warps = list(map(int, input().split())) warps = [0] + warps warps = np.array(warps, dtype=int) order_num = np.zeros(len(warps) + 1, dtype=int) p...
#!/usr/bin/env python3 import numpy as np # def input(): # return sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) warps = list(map(int, input().split())) warps = [0] + warps warps = np.array(warps, dtype=int) order_num = np.zeros(len(warps) + 1, dtype=int) p...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
186
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<int> next(n); vector<int> order; order.push_back(0); for (int i = 0; i < n; ++i) { int a; cin >> a; a--; next[i] = a; } int now = 0; set<int> seen; seen.insert(0); int memo = -1; for...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<int> next(n); vector<int> order; order.push_back(0); for (int i = 0; i < n; ++i) { int a; cin >> a; a--; next[i] = a; } int now = 0; set<int> seen; seen.insert(0); int memo = -1; for...
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 13]]
1
249
if __name__ == '__main__': n,k = map(int,input().split()) A = [0] AA= list(map(int,input().split())) A = A + AA B = set() cnt = 0 ind = 1 startind = 0 D = [] while True: if A[ind] not in B: B.add(ind) D.append(ind) cnt += 1 ...
if __name__ == '__main__': n,k = map(int,input().split()) A = [0] AA= list(map(int,input().split())) A = A + AA B = set() cnt = 0 ind = 1 startind = 0 D = [] while True: if A[ind] not in B: B.add(ind) D.append(ind) cnt += 1 ...
[["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 20]]
5
223
N,K=map(int,input().split()) A=list(map(int,input().split())) B=[0]*(N+1) B[0]=1;c=0;d=0 if B[0] in A:c=B[0] for i in range(1,N+1): B[i]=A[B[i-1]-1] # if c==B[i]:break # if A.count(B[i])>1 and d==0:c=B[i];d+=1 d=B.index(B[-1])+1 #print(B.index(B[N-1])) #print(B,d) #print(d+1+(K-d-1)%(N-d-1)) #print(B[K],K,d,(K+1-...
N,K=map(int,input().split()) A=list(map(int,input().split())) B=[0]*(N+1) B[0]=1;c=0;d=0 if B[0] in A:c=B[0] for i in range(1,N+1): B[i]=A[B[i-1]-1] # if c==B[i]:break # if A.count(B[i])>1 and d==0:c=B[i];d+=1 d=B.index(B[-1])+1 #print(B.index(B[N-1])) #print(B,d) #print(d+1+(K-d-1)%(N-d-1)) #print(B[K],K,d,(K+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]]
5
188
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n + 1, 0); for (ll i = 1; i <= n; i++) cin >> a[i]; vector<ll> num(n + 1, 0); vector<ll> firstVisitNum(n + 1, 0); ll cnt_cycle = 1; ll tmpIndex = 1; num[tmpIndex]++; while (...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n + 1, 0); for (ll i = 1; i <= n; i++) cin >> a[i]; vector<ll> num(n + 1, 0); vector<ll> firstVisitNum(n + 1, 0); ll cnt_cycle = 1; ll tmpIndex = 1; num[tmpIndex]++; while (...
[["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
1
257
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a.at(i); vector<int> b(0); vector<int> kanri(n, -1); int y = 0; //現在地-1 while (kanri.at(y) == -1) { kanri.at(y) += b.size(); b.push_back(y + 1...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a.at(i); vector<int> b(0); vector<int> kanri(n, -1); int y = 0; //現在地-1 while (kanri.at(y) == -1) { kanri.at(y) = b.size(); b.push_back(y + 1)...
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 13]]
1
186
#define _CRT_SECURE_NO_WARNINGS #pragma warning(disable : 4244) // 最悪をします #include <algorithm> #include <assert.h> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include...
#define _CRT_SECURE_NO_WARNINGS #pragma warning(disable : 4244) // 最悪をします #include <algorithm> #include <assert.h> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
9,852
#include <bits/stdc++.h> typedef long long lint; using namespace std; struct loop { lint loop_len; lint prefix_len; }; lint n, k; vector<int> a; int f(int p) { return a[p]; } int simple_solve(int start, int m) { int now = start; for (int i = 0; i < m; i++) { now = f(now); } return now; } loop get_l...
#include <bits/stdc++.h> typedef long long lint; using namespace std; struct loop { lint loop_len; lint prefix_len; }; lint n, k; vector<int> a; int f(int p) { return a[p]; } int simple_solve(int start, int m) { int now = start; for (int i = 0; i < m; i++) { now = f(now); } return now; } loop get_l...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
296
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; ll k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) cin >> a[i]; vector<ll> s; vector<ll> ord(n + 1, -1); ll c = 1, l = 0; ll v = 1; while ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; ll k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) cin >> a[i]; vector<ll> s; vector<ll> ord(n + 1, -1); ll c = 1, l = 0; ll v = 1; while ...
[["-", 341, 342, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 341, 342, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 12, 69, 341, 342, 0, 16, 31, 16, 17, 109], ["-", 12, 69, 341, 342, 0, 16, 31, 16, 12, 22]]
1
210
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n, k; cin >> n >> k; vector<vector<ll>> doub(62, vector<ll>(n, 0)); for (ll i = 0; i < n; i++) { cin >> doub[0][i]; doub[0][i]--; } for (ll i = 0; i < 61; i++) ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n, k; cin >> n >> k; vector<vector<ll>> doub(62, vector<ll>(n, 0)); for (ll i = 0; i < n; i++) { cin >> doub[0][i]; doub[0][i]--; } for (ll i = 0; i < 61; i++) ...
[["-", 15, 339, 51, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 339, 51, 16, 31, 23, 0, 16, 17, 151], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 17, 152], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 12, 22]]
1
209
#include <bits/stdc++.h> #define newl "\n" using namespace std; using lli = long long int; using vvint = vector<vector<int>>; const int mod = 1e9 + 7; const int N = 2e5 + 1; void dfs(int s, vector<int> &a, vector<bool> &vis, vector<int> &chain, int &node) { vis[s] = 1; chain.push_back(s); if (!vis[a[s]...
#include <bits/stdc++.h> #define newl "\n" using namespace std; using lli = long long int; using vvint = vector<vector<int>>; const int mod = 1e9 + 7; const int N = 2e5 + 1; void dfs(int s, vector<int> &a, vector<bool> &vis, vector<int> &chain, int &node) { vis[s] = 1; chain.push_back(s); if (!vis[a[s]...
[["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
419
from collections import deque N, K = map(int, input().split()) towns = [0] + list(map(int, input().split())) checked = [-1 for _ in range(N+1)] checked[1] = 0 next = towns[1] count = 1 while(checked[next] < 0): checked[next] = count count += 1 next = towns[next] loop = count - checked[next] pos = 0 if K > c...
from collections import deque N, K = map(int, input().split()) towns = [0] + list(map(int, input().split())) checked = [-1 for _ in range(N+1)] checked[1] = 0 next = towns[1] count = 1 while(checked[next] < 0): checked[next] = count count += 1 next = towns[next] loop = count - checked[next] pos = 0 if K >= ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20]]
5
161
#include <algorithm> #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> const int INF = 0x7fffffff; us...
#include <algorithm> #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> const int INF = 0x7fffffff; us...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
350
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // fixed, setprecis...
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> // fixed, setprecis...
[["-", 31, 16, 12, 23, 0, 41, 15, 16, 17, 19], ["+", 31, 16, 12, 23, 0, 41, 15, 16, 17, 18]]
1
224
//ループ検知 #include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < (N); ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; const int inf{int(1e9)}; int main(void) { int N; ll K; cin >> N >> K; vector<int> A(N); rep(i, N) { cin >> A[i]; } vector<...
//ループ検知 #include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < (N); ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int, int>; const int inf{int(1e9)}; int main(void) { int N; ll K; cin >> N >> K; vector<int> A(N); rep(i, N) { cin >> A[i]; } vector<...
[["+", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["+", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13]]
1
228
from collections import defaultdict def main(): n, k = map(int, input().split(" ")) a = list(map(int, input().split(" "))) s = [] ord = [-1]*(n) u = 1 while ord[u] == -1: ord[u] = len(s) s.append(u) u = a[u-1] l = len(s) - ord[u] if k < ord[u]: print(s[k])...
from collections import defaultdict def main(): n, k = map(int, input().split(" ")) a = list(map(int, input().split(" "))) s = [] ord = [-1]*(n+1) u = 1 while ord[u] == -1: ord[u] = len(s) s.append(u) u = a[u-1] l = len(s) - ord[u] if k < ord[u]: print(s[k...
[["+", 0, 662, 12, 657, 12, 23, 0, 657, 17, 72], ["+", 0, 662, 12, 657, 12, 23, 0, 657, 12, 612]]
5
159
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pa pair<int, int> #define pal pair<long long, long long> #define pali pair<long long, int> #define pad pair<double, double> #define pb push_back #define mp make_pair #define COUT(v) ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pa pair<int, int> #define pal pair<long long, long long> #define pali pair<long long, int> #define pad pair<double, double> #define pb push_back #define mp make_pair #define COUT(v) ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
1,329
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import defaultdict def main(): n, k, *a = map(int, read().split()) cur_town = 0 transits = set() tran_time = defaultdict(int) cnt = 0 while True: if k == 0: print(cur_town) sys.exit...
import sys read = sys.stdin.read readlines = sys.stdin.readlines from collections import defaultdict def main(): n, k, *a = map(int, read().split()) cur_town = 0 transits = set() tran_time = defaultdict(int) cnt = 0 while True: if k == 0: print(cur_town + 1) sys....
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
156
/*input 6 727202214173249351 6 5 2 5 3 2 */ #include <algorithm> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric> #include <que...
/*input 6 3 6 5 2 5 3 2 */ #include <algorithm> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set...
[["-", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
569
from copy import deepcopy def main(): n, k = map(int, input().split()) a = [int(x)-1 for x in input().split()] visited = set() i = 0 cnt = 0 # 途中で前に行ったところに行ったら終わり # kが小さくてcnt == kになってもおわり while True: if i in visited: break visited.add(i) cnt += 1 ...
from copy import deepcopy def main(): n, k = map(int, input().split()) a = [int(x)-1 for x in input().split()] visited = set() i = 0 cnt = 0 # 途中で前に行ったところに行ったら終わり # kが小さくてcnt == kになってもおわり while True: if i in visited: break visited.add(i) cnt += 1 ...
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
170
259 N,K=map(int,input().split()) A=[0]+list(map(int,input().split())) m=1 towns=[1] flg=[0]*(N+1) flg[1]=1 while 1: m=A[m] towns.append(m) if flg[m]==1: l=len(towns)-towns.index(m)-1 break flg[m]=1 pl=towns.index(m) if K<=pl: print(pl) else: print(towns[(K-pl)%l+pl])
259 N,K=map(int,input().split()) A=[0]+list(map(int,input().split())) m=1 towns=[1] flg=[0]*(N+1) flg[1]=1 while 1: m=A[m] towns.append(m) if flg[m]==1: l=len(towns)-towns.index(m)-1 break flg[m]=1 pl=towns.index(m) if K<=pl: print(towns[K]) else: print(towns[(K-pl)%l+pl])
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 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, 206, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73]]
5
142
def main(): n, k = map(int, input().split()) a_list = list(map(int, input().split())) visited_list = [-1] * n # 何ワープ目で訪れたか visited_list[0] = 0 city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数 for i in range(1, n + 1): city = a_list[city - 1] if visited_list[ci...
def main(): n, k = map(int, input().split()) a_list = list(map(int, input().split())) visited_list = [-1] * n # 何ワープ目で訪れたか visited_list[0] = 0 city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数 for i in range(1, n + 1): city = a_list[city - 1] if visited_list[ci...
[["+", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 12, 612]]
5
190
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; static int dl[65][200000]; for (size_t i = 1; i <= n; i++) { cin >> dl[0][i]; } for (size_t i = 1; i < 65; i++) { for (size_t j = 1; j <= n; j++) { dl[i][j] = dl[i - 1][dl[i - 1][j]]; } } int a...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; static int dl[65][200000]; for (size_t i = 1; i <= n; i++) { cin >> dl[0][i]; } for (size_t i = 1; i < 64; i++) { for (size_t j = 1; j <= n; j++) { dl[i][j] = dl[i - 1][dl[i - 1][j]]; } } int a...
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
167
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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) { a = b; return 1; } return 0; } const int INF = 10010...
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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) { a = b; return 1; } return 0; } const int INF = 10010...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
269
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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) { a = b; return 1; } return 0; } const int mod = 1000...
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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) { a = b; return 1; } return 0; } const int mod = 1000...
[["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
1
269
N,K = map(int,input().split()) A = list(map(int,input().split())) A.insert(0,0) B = {1:1} x = A[1] st = 0 while True: if x not in B: B[x] = 1 x = A[x] else: st = x break x = 1 t = 0 while x!=st: x = A[x] t += 1 x = st x = A[x] T = 1 while x!=st: x = A[x] T += 1 if...
N,K = map(int,input().split()) A = list(map(int,input().split())) A.insert(0,0) B = {1:1} x = A[1] st = 0 while True: if x not in B: B[x] = 1 x = A[x] else: st = x break x = 1 t = 0 while x!=st: x = A[x] t += 1 x = st x = A[x] T = 1 while x!=st: x = A[x] T += 1 if...
[["-", 0, 57, 64, 196, 0, 52, 15, 666, 0, 22], ["+", 0, 57, 64, 196, 0, 52, 15, 666, 0, 22]]
5
193
N, K = map(int, input().split()) warp = list(map(int, input().split())) warp = [i - 1 for i in warp] visit = [0] current_loc = 0 while warp[current_loc] != -1: visit.append(warp[current_loc]) warp[current_loc] = -1 current_loc = visit[-1] res = visit.index(visit[-1]) cycle = visit[res + 1:] if K <= res: prin...
N, K = map(int, input().split()) warp = list(map(int, input().split())) warp = [i - 1 for i in warp] visit = [0] current_loc = 0 while warp[current_loc] != -1: visit.append(warp[current_loc]) warp[current_loc] = -1 current_loc = visit[-1] res = visit.index(visit[-1]) cycle = visit[res + 1:] if K <= res: prin...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
148
n, k = map(int, input().split()) a = list(map(int, input().split())) rec = [0] i = 0 flag = [0 for _ in range(n + 1)] while True: if flag[rec[i]] == 0: flag[rec[i]] = 1 rec.append(a[rec[i]] - 1) else: start = rec.index(a[rec[i]] - 1) loop = rec[start:] pre = rec[:start] ...
n, k = map(int, input().split()) a = list(map(int, input().split())) rec = [0] i = 0 flag = [0 for _ in range(n + 1)] while True: if flag[rec[i]] == 0: flag[rec[i]] = 1 rec.append(a[rec[i]] - 1) else: start = rec.index(a[rec[i]] - 1) loop = rec[start:] pre = rec[:start] ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 18], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 19], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 652, 3, 4, 0, 657, 31, 206, 51, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
169
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 18:05:47 2020 @author: liang """ N, K = map(int, input().split()) A = [int(x) for x in input().split()] visited = [-1]*N loop = list() cur = 1 cnt = 0 while visited[cur-1] == -1: #while True: visited[cur-1] = cnt loop.append(cur) cnt += 1 cur = A[cur-...
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 18:05:47 2020 @author: liang """ N, K = map(int, input().split()) A = [int(x) for x in input().split()] visited = [-1]*N loop = list() cur = 1 cnt = 0 while visited[cur-1] == -1: #while True: visited[cur-1] = cnt loop.append(cur) cnt += 1 cur = A[cur-...
[["-", 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, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
150
#include <bits/stdc++.h> using namespace std; int main() { long long N; long long K; cin >> N >> K; vector<long long> A(N), B(N, -1); for (long long i = 0; i < N; i++) { cin >> A[i]; A[i]--; } B[0] = 0; long long pos = 0, shuuki = 0; long long machi; for (long long i = 1; i <= K; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long N; long long K; cin >> N >> K; vector<long long> A(N), B(N, -1); for (long long i = 0; i < N; i++) { cin >> A[i]; A[i]--; } B[0] = 0; long long pos = 0, shuuki = 0; long long machi; for (long long i = 1; i <= K; i++) { ...
[["+", 0, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
244
n,k = map(int,input().split()) A=list(map(int,input().split()) ) kyori = [-1] *len(A) junban =[] x=0 d=0 while kyori[x] == -1: junban.append(x) kyori[x]=d d+=1 x=A[x]-1 roop_x = x roop_d = d - kyori[x] if k<d: print(junban[k]+1) else: k0 = kyori[x]-1 k1 = (k-k0)...
n,k = map(int,input().split()) A=list(map(int,input().split()) ) kyori = [-1] *len(A) junban =[] x=0 d=0 while kyori[x] == -1: junban.append(x) kyori[x]=d d+=1 x=A[x]-1 roop_x = x roop_d = d - kyori[x] # for k in range(100): if k<d: print(junban[k]+1) else: k0 = ky...
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
141
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long k; cin >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<bool> visit(n + 1, false); int now = 1; long long leng = 0; while (true) { if (visit[now]) break; visit[now] =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long k; cin >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<bool> visit(n + 1, false); int now = 1; long long leng = 0; while (true) { if (visit[now]) break; visit[now] =...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
1
231
#include <algorithm> #include <iostream> using namespace std; int main(void) { int a[200001], b[200001], c[200001], i, j, n, ans, rep; long long int k; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a[i]; b[i] = 0; c[i] = 0; } ans = 0; i = 1; while (1) { if (b[i] == 0) { b[i] = 1...
#include <algorithm> #include <iostream> using namespace std; int main(void) { int a[200001], b[200001], c[200001], i, j, n, ans, rep; long long int k; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a[i]; b[i] = 0; c[i] = 0; } ans = 0; i = 1; while (1) { if (b[i] == 0) { b[i] = 1...
[["-", 64, 9, 0, 1, 0, 16, 12, 69, 28, 22], ["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 73]]
1
210
N,K = map(int,input().split()) A = list(map(lambda x:int(x)-1,input().split())) i = 0 visited = set([0]) while K > 0: i = A[i] K -= 1 if i in visited: break visited.add(i) if K == 0: print(i) exit(0) ls = [i] j = i while True: j = A[j] if j == i: break ls.append(j) p...
N,K = map(int,input().split()) A = list(map(lambda x:int(x)-1,input().split())) i = 0 visited = set([0]) while K > 0: i = A[i] K -= 1 if i in visited: break visited.add(i) if K == 0: print(i+1) exit(0) ls = [i] j = i while True: j = A[j] if j == i: break ls.append(j)...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
134
def delete_head_zeros(n): n = str(n) l = len(n) if "." in n: l = n.find(".") head_zeros = 0 for i in range(l - 1): if n[i] == "0": head_zeros += 1 else: break return n[head_zeros:] # compare a, b # a, b: int or string def bigint_compare(a, b): a = delete_head_zeros(a) b = delete_head_zeros(b) if ...
def delete_head_zeros(n): n = str(n) l = len(n) if "." in n: l = n.find(".") head_zeros = 0 for i in range(l - 1): if n[i] == "0": head_zeros += 1 else: break return n[head_zeros:] # compare a, b # a, b: int or string def bigint_compare(a, b): a = delete_head_zeros(a) b = delete_head_zeros(b) if ...
[["-", 0, 14, 8, 196, 0, 57, 15, 666, 667, 19], ["+", 0, 14, 8, 196, 0, 57, 15, 666, 667, 18], ["-", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["-", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["-", 3, 4, 0, 657, 31, 206, 206, 657, 17, 33], ["-", 3, 4, 0, 657, 31, 206, 206, 657, 12, 612]]
5
949
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stdlib.h> #include <vector> // freopen(".in","r",stdin); // freopen(".out","w",stdout); // freopen("input.txt","r",stdin); /...
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stdlib.h> #include <vector> // freopen(".in","r",stdin); // freopen(".out","w",stdout); // freopen("input.txt","r",stdin); /...
[["-", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22]]
1
441
n,k = map(int,input().split()) button = list(map(int,input().split())) visit = [-1]*n hisitory = [-1] push = 0 f = 0 for i in range(k): visit[push] = i+1 hisitory.append(push) push = button[push] -1 if(visit[push] != -1): f = 1 start = visit[push] last=push end = i+1 ...
n,k = map(int,input().split()) button = list(map(int,input().split())) visit = [-1]*n hisitory = [-1] push = 0 f = 0 for i in range(k): visit[push] = i+1 hisitory.append(push) push = button[push] -1 if(visit[push] != -1): f = 1 start = visit[push] last=push end = i+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, 657, 17, 72], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73]]
5
177
#include <bits/stdc++.h> using namespace std; // NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER // ABC 167, task d, 2020/09/03 // ms, /* */ int main(void) { int N; int64_t K; vector<int> a; map<int, int> report; // key:訪れた町, value:遷移回数 int loc = 0; int mv_ctr = 0; int cycle; int ans_ctr; int ans;...
#include <bits/stdc++.h> using namespace std; // NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER // ABC 167, task d, 2020/09/03 // ms, /* */ int main(void) { int N; int64_t K; vector<int> a; map<int, int> report; // key:訪れた町, value:遷移回数 int loc = 0; int mv_ctr = 0; int cycle; int ans_ctr; int ans;...
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 73]]
1
208
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(x) x.begin(), x.end() using ll = long long; using pii = pair<int, int>; using vi = vector<int>; const int mod = 1e9 + 7; const ll INF = 1e18; const int MAX = 1e6...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(x) x.begin(), x.end() using ll = long long; using pii = pair<int, int>; using vi = vector<int>; const int mod = 1e9 + 7; const ll INF = 1e18; const int MAX = 1e6...
[["-", 64, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 73], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
1
342
N, K = map(int, input().split()) A = list(map(int, input().split())) A.insert(0, 0) v = [-1] * (N + 1) n = 1 f = 0 for i in range(N): v[n] = i n = A[n] if v[n] != -1: f = 1 s = n #ループのスタート t = i l = t - v[s] + 1 break if t >= K: print(v.index(K)) else: K = ...
N, K = map(int, input().split()) A = list(map(int, input().split())) A.insert(0, 0) v = [-1] * (N + 1) n = 1 f = 0 for i in range(N): v[n] = i n = A[n] if v[n] != -1: f = 1 s = n #ループのスタート t = i l = t - v[s] + 1 break if t >= K: print(v.index(K)) else: K = ...
[["+", 12, 657, 31, 23, 0, 657, 12, 206, 51, 22], ["+", 12, 657, 31, 23, 0, 657, 12, 206, 0, 70], ["+", 12, 657, 31, 23, 0, 657, 12, 206, 0, 73], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 51, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 0, 70], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 0, 73]]
5
145
import sys from collections import deque N, K = map(int, sys.stdin.readline().strip().split()) tmp = list(map(int, sys.stdin.readline().strip().split())) A = [a-1 for a in tmp] visited = set() loop = [] q = deque() q.append(0) start = float("inf") end = float("inf") count = 0 while q and count < K: s_town = q....
import sys from collections import deque N, K = map(int, sys.stdin.readline().strip().split()) tmp = list(map(int, sys.stdin.readline().strip().split())) A = [a-1 for a in tmp] visited = set() loop = [] q = deque() q.append(0) start = float("inf") end = float("inf") count = 0 while q and count <= N: s_town = q...
[["-", 0, 656, 0, 52, 15, 679, 12, 666, 667, 18], ["-", 0, 656, 0, 52, 15, 679, 12, 666, 0, 22], ["+", 0, 656, 0, 52, 15, 679, 12, 666, 667, 19], ["+", 0, 656, 0, 52, 15, 679, 12, 666, 0, 22]]
5
208
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x....
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x....
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
356
N , K = map(int,input().split()) A = list(map(int,input().split())) reach = [-1 for i in range(N)] reach[0] = 0 #最初の町は0回でいく now = 0 #loop = 1 dic ={} dic[0] = 0 for i in range(N): to = A[now]-1 if reach[to] != -1: ini = i+1 #print(i,to,reach[to]) loop = i+1 - reach[to] break if i+1 not in dic: ...
N , K = map(int,input().split()) A = list(map(int,input().split())) reach = [-1 for i in range(N)] reach[0] = 0 #最初の町は0回でいく now = 0 #loop = 1 dic ={} dic[0] = 0 for i in range(N): to = A[now]-1 if reach[to] != -1: ini = i+1 #print(i,to,reach[to]) loop = i+1 - reach[to] break if i+1 not in dic:...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 19], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 18]]
5
178
def resolve(): N, K = list(map(int, input().split())) A = list(map(lambda x: int(x)-1, input().split())) routes = [0] current = 0 visited = [False for _ in range(N)] visited[0] = True while visited[A[current]] is False: current = A[current] routes.append(current) visi...
def resolve(): N, K = list(map(int, input().split())) A = list(map(lambda x: int(x)-1, input().split())) routes = [0] current = 0 visited = [False for _ in range(N)] visited[0] = True while visited[A[current]] is False: current = A[current] routes.append(current) visi...
[["+", 0, 652, 3, 4, 0, 41, 0, 657, 17, 72], ["+", 0, 652, 3, 4, 0, 41, 0, 657, 12, 612]]
5
162
#include <algorithm> #include <array> #include <bitset> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #includ...
#include <algorithm> #include <array> #include <bitset> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #includ...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
1
2,323
N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) B = [-1 for i in range(N+1)] B[1] = 0 n = 1 m = 0 while 1: n = A[n] m += 1 if m == K: break if B[n] == -1: B[n] = m else: a = (K - m) % (m - B[n]) for i in range(a): n = A[n] print(n) break
N, K = map(int, input().split()) A = [0] + list(map(int, input().split())) B = [-1 for i in range(N+1)] B[1] = 0 n = 1 m = 0 while 1: n = A[n] m += 1 if m == K: print(n) break if B[n] == -1: B[n] = m else: a = (K - m) % (m - B[n]) for i in range(a): n = A[n] print(n) break
[["+", 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, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
134
import copy N, K = map(int, input().split()) A = list(map(int, input().split())) routes = [0] visited = [False] * N visited[0] = True now = 0 while True: next_town = A[now] - 1 if visited[next_town]: routes.append(next_town) break visited[next_town] = True routes.append(next_town) no...
import copy N, K = map(int, input().split()) A = list(map(int, input().split())) routes = [0] visited = [False] * N visited[0] = True now = 0 while True: next_town = A[now] - 1 if visited[next_town]: routes.append(next_town) break visited[next_town] = True routes.append(next_town) no...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
175
n,k=map(int,input().split()) a=list(map(int,input().split())) now=0 visited=set() visited.add((0)) visited2=[0] while True: k-=1 now=a[now]-1 if k==0: print(now-1) exit() if now in visited: visited.add((now)) visited2.append(now) break visited.add((now)) visited2.append(now)...
n,k=map(int,input().split()) a=list(map(int,input().split())) now=0 visited=set() visited.add((0)) visited2=[0] while True: k-=1 now=a[now]-1 if k==0: print(now+1) exit() if now in visited: visited.add((now)) visited2.append(now) break visited.add((now)) visited2.append(now) x...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72]]
5
190