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> using namespace std; #define ll long long int #define ff(i, n) for (i = 0; i < n; i++) #define pb push_back ll bg = 9982443598893; ll power(ll x, ll y) { if (y == 0) return 1; ll d = power(x, y / 2); ll f = (d * d); if (y % 2 == 0) return f; else return (f * x); } int main...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ff(i, n) for (i = 0; i < n; i++) #define pb push_back ll bg = 9982443598893; ll power(ll x, ll y) { if (y == 0) return 1; ll d = power(x, y / 2); ll f = (d * d); if (y % 2 == 0) return f; else return (f * x); } int main...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
310
n, k = map(int, input().split()) an = list(map(int, input().split())) tp = [] current = 1 tp.append(1) if k > n: for i in range(n): current = an[current-1] tp.append(current) tps = len(set(tp)) tp = tp[0:tps] kurikaesi_start = an[tp[-1]-1] start_ind = tp.index(kurikaesi_start) num = (k - star...
n, k = map(int, input().split()) an = list(map(int, input().split())) tp = [] current = 1 tp.append(1) if k > n: for i in range(n): current = an[current-1] tp.append(current) tps = len(set(tp)) tp = tp[0:tps] kurikaesi_start = an[tp[-1]-1] start_ind = tp.index(kurikaesi_start) num = (k - star...
[["+", 0, 1, 0, 662, 12, 206, 206, 657, 17, 33], ["+", 0, 1, 0, 662, 12, 206, 206, 657, 12, 612]]
5
152
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <queue> #include <string> #include <time.h> #include <vector> int main(void) { long N, K; std::cin >> N >> K; long A[200000] = {}; for (long i = 0; i < N; i++) { std::cin >> A[i]; } std::vector<lon...
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <queue> #include <string> #include <time.h> #include <vector> int main(void) { long N, K; std::cin >> N >> K; long A[200000] = {}; for (long i = 0; i < N; i++) { std::cin >> A[i]; } std::vector<lon...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 72], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
314
#include <bits/stdc++.h> using namespace std; long long teleport(long long start, long long num, vector<long long> *A) { long long now = start; for (long long i = 0; i < num; i++) { now = (*A)[now]; } return now; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); long long N, K; long l...
#include <bits/stdc++.h> using namespace std; long long teleport(long long start, long long num, vector<long long> *A) { long long now = start; for (long long i = 0; i < num; i++) { now = (*A)[now]; } return now; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); long long N, K; long l...
[["-", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 15, 339, 51, 16, 12, 23, 0, 16, 31, 22], ["-", 15, 339, 51, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 57, 15, 339, 51, 16, 12, 23, 0, 25]]
1
356
// In the name of god #include <bits/stdc++.h> #pragma GCC optimze("02") using namespace std; using ll = long long; const ll maxn = 2e5 + 5, inf = 1e18 + 5, lg = 15; ll n, k, a[maxn], v; bool mark[maxn], b; vector<ll> door; vector<ll> gd; vector<ll> gd2; vector<ll> adj[maxn]; void dfs(int u) { mark[u] = 1; gd2.push...
// In the name of god #include <bits/stdc++.h> #pragma GCC optimze("02") using namespace std; using ll = long long; const ll maxn = 2e5 + 5, inf = 1e18 + 5, lg = 15; ll n, k, a[maxn], v; bool mark[maxn], b; vector<ll> door; vector<ll> gd; vector<ll> gd2; vector<ll> adj[maxn]; void dfs(int u) { mark[u] = 1; gd2.push...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
351
#include <bits/stdc++.h> #define INF 1e9 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() #define endl "\n" template <class T> bool chmin(...
#include <bits/stdc++.h> #define INF 1e9 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() #define endl "\n" template <class T> bool chmin(...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
469
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vl vector<ll> int main() { ll N, K; cin >> N >> K; vl A; ll a; A.push_back(0); for (ll i = 0; i < N; ++i) { cin >> a; A.push_back(a); } vl B; set<ll> visited; B.push_back(1); visited.insert(1); ll next; ...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vl vector<ll> int main() { ll N, K; cin >> N >> K; vl A; ll a; A.push_back(0); for (ll i = 0; i < N; ++i) { cin >> a; A.push_back(a); } vl B; set<ll> visited; B.push_back(1); visited.insert(1); ll next; ...
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
1
270
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; void read(); template <typename First, typename... Rest> void read(First &f...
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; void read(); template <typename First, typename... Rest> void read(First &f...
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22]]
1
456
n,k = map(int,input().split()) A = list(map(int,input().split())) t = 0 c = 0 ans = [0] * n L = [] s = 0 for _ in range(k): if ans[t] == 1: n = len(L) - L.index(t) temp = t + k%n temp %= n t = L[L.index(t):][temp] break else: ans[t] = 1 L.append(t) ...
n,k = map(int,input().split()) A = list(map(int,input().split())) t = 0 c = 0 ans = [0] * n L = [] s = 0 for _ in range(k): if ans[t] == 1: n = len(L) - L.index(t) temp = (k-c)%n t = L[L.index(t):][temp] break else: ans[t] = 1 L.append(t) t = A[t]-1 ...
[["-", 64, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["-", 64, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 24], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 12, 22], ["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 25], ["-", 0, 1, 0, 662, 12, 657, 12, 657, 1...
5
139
#include <iostream> #include <vector> using namespace std; typedef long long ll; ll n; int a[200005]; ll k; vector<int> g; ll tmp; ll u; bool use[200005]; int dist[200005]; void dfs(int v, ll d) { if (use[v]) { u = v; tmp = d - dist[v]; return; } g.push_back(v); use[v] = true; dist[v] = d;...
#include <iostream> #include <vector> using namespace std; typedef long long ll; ll n; int a[200005]; ll k; vector<int> g; ll tmp; ll u; bool use[200005]; int dist[200005]; void dfs(int v, ll d) { if (use[v]) { u = v; tmp = d - dist[v]; return; } g.push_back(v); use[v] = true; dist[v] = d;...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
228
#include <bits/stdc++.h> #define f(i, a, b) for (ll i = a; i < (ll)b; i++) #define af(i, a, b) for (ll i = a; i >= (ll)b; i--) #define rep(i, a, b, k) for (ll i = a; i < (ll)b; i += k) #define arep(i, a, b, k) for (ll i = a; i >= (ll)b; i -= k) #define fs first #define sc second #define pb push_back #define mp make_pa...
#include <bits/stdc++.h> #define f(i, a, b) for (ll i = a; i < (ll)b; i++) #define af(i, a, b) for (ll i = a; i >= (ll)b; i--) #define rep(i, a, b, k) for (ll i = a; i < (ll)b; i += k) #define arep(i, a, b, k) for (ll i = a; i >= (ll)b; i -= k) #define fs first #define sc second #define pb push_back #define mp make_pa...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22]]
1
327
#include <assert.h> #include <math.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long ll; typedef long double ld; #define rep(i, l, r) for (ll i = (l); i < (r); i++) #define repp(i, l, r, k) for (ll i = (l); i < (r); i += (k)) #define rrep(i, l, r) for (ll i = (l); i >=...
#include <assert.h> #include <math.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long ll; typedef long double ld; #define rep(i, l, r) for (ll i = (l); i < (r); i++) #define repp(i, l, r, k) for (ll i = (l); i < (r); i += (k)) #define rrep(i, l, r) for (ll i = (l); i >=...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
0
2,014
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--) using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<v...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--) using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<v...
[["-", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 70], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 73], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
286
#include <bits/stdc++.h> using namespace std; #define C continue; #define R return #define D double #define I insert #define ll long long #define ld long double #define ull unsigned long long #define ui unsigned int #define pb push_back #define pf push_front #define vi vector<int> #define vc vector<char> #define v...
#include <bits/stdc++.h> using namespace std; #define C continue; #define R return #define D double #define I insert #define ll long long #define ld long double #define ull unsigned long long #define ui unsigned int #define pb push_back #define pf push_front #define vi vector<int> #define vc vector<char> #define v...
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
573
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cfloat> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstre...
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cfloat> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstre...
[["+", 64, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 64, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
680
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { ll n, k; cin >> n >> k; vector<int> v(n + 5), vis(n + 5, -1); for (int i = 1; i <= n; i++) cin >> v[i]; int i, ans = 1, cl = 0; vis[1] = 0; for (i = 1; i <= k; i++) { ans = v[ans]; if (vis[ans] != -1) { ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { ll n, k; cin >> n >> k; vector<int> v(n + 5), vis(n + 5, -1); for (int i = 1; i <= n; i++) cin >> v[i]; int i, ans = 1, cl = 0; vis[1] = 0; for (i = 1; i <= k; i++) { ans = v[ans]; if (vis[ans] != -1) { ...
[["+", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 51, 22], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46]]
1
207
/** * Created by hiramekun at 20:39 on 2020-05-10. */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using P = pair<ll, ll>; template <typename T> using pq = priority_queue<T>; template <typename T> using minpq = priority_q...
/** * Created by hiramekun at 20:39 on 2020-05-10. */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using P = pair<ll, ll>; template <typename T> using pq = priority_queue<T>; template <typename T> using minpq = priority_q...
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
1
563
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N, K; cin >> N >> K; vector<int> v; for (int i = 0; i < N; i++) { int a; cin >> a; a--; v.push_back(a); } vector<int> zzz; zzz.push_back(0); map<int, int> mp; mp[0] = 0; int now = 0; for (int i = 0...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N, K; cin >> N >> K; vector<int> v; for (int i = 0; i < N; i++) { int a; cin >> a; a--; v.push_back(a); } vector<int> zzz; zzz.push_back(0); map<int, int> mp; mp[0] = 0; int now = 0; for (int i = 0...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
255
#include <bits/stdc++.h> #define in freopen("input.txt", "r", stdin); #define out freopen("output.txt", "w", stdout); #define clr(arr, key) memset(arr, key, sizeof arr) #define pb push_back #define mp(a, b) make_pair(a, b) #define infinity (1 << 28) #define LL long long #define PI acos(-1) #define gcd(a, b) __gcd(a, b...
#include <bits/stdc++.h> #define in freopen("input.txt", "r", stdin); #define out freopen("output.txt", "w", stdout); #define clr(arr, key) memset(arr, key, sizeof arr) #define pb push_back #define mp(a, b) make_pair(a, b) #define infinity (1 << 28) #define LL long long #define PI acos(-1) #define gcd(a, b) __gcd(a, b...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
527
n,k=map(int,input().split()) ar=list(map(int,input().split())) vis=[0 for i in range(n+1)] x=1 seq=[1] go=0 rep=0 ct=1 while (vis[x]==0): vis[x]=ct seq.append(ar[x-1]) x=ar[x-1] ct+=1 if vis[x]!=0: rep=ct-vis[x] go=vis[x] if k<=go: print(seq[k-1]) else: print(seq[go+(k-go)%re...
n,k=map(int,input().split()) ar=list(map(int,input().split())) vis=[0 for i in range(n+1)] x=1 seq=[1] go=0 rep=0 ct=1 while (vis[x]==0): vis[x]=ct seq.append(ar[x-1]) x=ar[x-1] ct+=1 if vis[x]!=0: rep=ct-vis[x] go=vis[x] if k<=go: print(seq[k]) else: print(seq[go+(k-go)%rep]...
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
155
N, K = map(int, input().split()) A = list(map(int, input().split())) B = [0] * N C = [] C.append(0) now = 0 B[0] = 1 for i in range(N): now = A[now] - 1 if B[now] == 1: break else: C.append(now) B[now] = 1 mae = 0 for i in range(len(C)): if C[i] == now: mae = i ...
N, K = map(int, input().split()) A = list(map(int, input().split())) B = [0] * N C = [] C.append(0) now = 0 B[0] = 1 for i in range(N): now = A[now] - 1 if B[now] == 1: break else: C.append(now) B[now] = 1 mae = 0 for i in range(len(C)): if C[i] == now: mae = i ...
[["-", 3, 4, 0, 657, 31, 206, 206, 657, 17, 72], ["-", 3, 4, 0, 657, 31, 206, 206, 657, 12, 612]]
5
175
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // #define int long long // #define double long double #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep1(i, n) for (int i = 1; i < (int)(n); ++i) #define repeq(i, n) for (int i = 0; i <= (int)(n); ++i) #define rep1eq(i, n) for (int ...
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // #define int long long // #define double long double #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep1(i, n) for (int i = 1; i < (int)(n); ++i) #define repeq(i, n) for (int i = 0; i <= (int)(n); ++i) #define rep1eq(i, n) for (int ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
1,089
#include <bits/stdc++.h> #include <unordered_set> using namespace std; typedef long long ll; typedef unsigned long long ull; using P = pair<ll, ll>; using V = vector<ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (l...
#include <bits/stdc++.h> #include <unordered_set> using namespace std; typedef long long ll; typedef unsigned long long ull; using P = pair<ll, ll>; using V = vector<ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++) #define rep2(i, m, n) for (ll i = m; i < (l...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
1
378
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; ll n, k; ll a[200005]; ll b[200005]; int main() { scanf("%lld%lld", &n, &k); for (ll i = 1; i <= n; i++) { scanf("%lld", &a[i]); } ll cnt = 1; ll i; for (i = 1; b[i] == 0; i = a[i], cnt++) { b[i] = cnt; k--; ...
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; ll n, k; ll a[200005]; ll b[200005]; int main() { scanf("%lld%lld", &n, &k); for (ll i = 1; i <= n; i++) { scanf("%lld", &a[i]); } ll cnt = 1; ll i; for (i = 1; b[i] == 0; i = a[i], cnt++) { b[i] = cnt; k--; ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
187
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long lo...
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long lo...
[["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
322
import sys n,k = list(map(int,input().split())) a = list(map(int,input().split())) kyori = [-1]*n now = 0;kyori[now] = 0 jyunkan = 0;v = 0 for i in range(n): tugi = a[now] - 1 if kyori[tugi] != -1: jyunkan = kyori[now] + 1 v = tugi break kyori[tugi] = kyori[now] + 1 if kyori[tu...
import sys n,k = list(map(int,input().split())) a = list(map(int,input().split())) kyori = [-1]*n now = 0;kyori[now] = 0 jyunkan = 0;v = 0 for i in range(n): tugi = a[now] - 1 if kyori[tugi] != -1: jyunkan = kyori[now] + 1 v = tugi break kyori[tugi] = kyori[now] + 1 if kyori[tu...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
179
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; ll arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; bool visit[n + 1]; for (int i = 1; i <= n; i++) visit[i] = false; ll tyme[n + 1]...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; ll arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; bool visit[n + 1]; for (int i = 1; i <= n; i++) visit[i] = false; ll tyme[n + 1]...
[["-", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
271
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define mp(x, y) make_pair(x, y) const int nax = 2e5 + 5; void solve() { ll n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } vector<int> v; vector<int> vis(n, -1); int ci =...
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define mp(x, y) make_pair(x, y) const int nax = 2e5 + 5; void solve() { ll n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } vector<int> v; vector<int> vis(n, -1); int ci =...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
320
/* Created by Ezio112 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define inf ll(10e16) #define mod ll(10e8 + 7) #define ff first #define ss second int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t; // cin>>t; t = 1; w...
/* Created by Ezio112 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define inf ll(10e16) #define mod ll(10e8 + 7) #define ff first #define ss second int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t; // cin>>t; t = 1; w...
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
1
206
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define _ov...
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define _ov...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
646
#include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define UM unordered_map...
#include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define UM unordered_map...
[["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22]]
1
302
#include <cstdio> long long n, k, a[500005], f[500005], cnt; int dfs(int i, int k) { if (k == 0) return i; if (!f[i]) return f[i] = cnt++, dfs(a[i], k - 1); else { k %= (cnt - f[i]); int ret = i; for (int i = 1; i <= k; i++) ret = a[ret]; return ret; } } int main() { scanf("%lld%...
#include <cstdio> long long n, k, a[500005], f[500005], cnt; int dfs(int i, long long k) { if (k == 0) return i; if (!f[i]) return f[i] = cnt++, dfs(a[i], k - 1); else { k %= (cnt - f[i]); int ret = i; for (int i = 1; i <= k; i++) ret = a[ret]; return ret; } } int main() { scanf(...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 40], ["+", 49, 53, 54, 55, 0, 56, 39, 86, 0, 96]]
1
171
if __name__ == '__main__': from sys import stdin # from collections import defaultdict # from collections import deque # from collections import Counter import numpy as np # import math # import random input = stdin.readline n, k = map(int, input().split()) aa = [0]+list(map(in...
if __name__ == '__main__': from sys import stdin # from collections import defaultdict # from collections import deque # from collections import Counter import numpy as np # import math # import random input = stdin.readline n, k = map(int, input().split()) aa = [0]+list(map(in...
[["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 18]]
5
167
#include <iostream> using namespace std; int ar[200001] = {}, bt[200001] = {}; int main() { int n; long long k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> ar[i]; bt[i] = -1; } int ord = 0, idx = 0, pv = -1; while (bt[idx] == -1 && ord < k) { bt[idx] = ord++; pv = idx; idx = ar...
#include <iostream> using namespace std; int ar[200001] = {}, bt[200001] = {}; int main() { int n; long long k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> ar[i]; bt[i] = -1; } int ord = 0, idx = 0, pv = -1; while (bt[idx] == -1 && ord < k) { bt[idx] = ord++; pv = idx; idx = ar...
[["-", 64, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
205
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) using i64 = int_fast64_t; using f64 = double; constexpr i64 INF = INT_FAST64_MAX / 2; constexpr f64 EPS = DBL_EPSILON; void solve() { i64 n, k; cin >> n >> k; vector<i64> as(n); for (auto &e : as) cin >> e, e--; vector<i64> ...
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) using i64 = int_fast64_t; using f64 = double; constexpr i64 INF = INT_FAST64_MAX / 2; constexpr f64 EPS = DBL_EPSILON; void solve() { i64 n, k; cin >> n >> k; vector<i64> as(n); for (auto &e : as) cin >> e, e--; vector<i64> ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
229
N, K = map(int, input().split()) A = list(map(int, input().split())) flag = [0] * (N+1) cnt = [0] * (N+1) now = 0 i = 1 while(flag[i] == 0 and K >= now): flag[i] = 1 cnt[i] = now i = A[i-1] now += 1 if(K < now): print(i) else: loop = now-cnt[i] kn = (K-now)%loop for j in range(kn): i = A[i-1] prin...
N, K = map(int, input().split()) A = list(map(int, input().split())) flag = [0] * (N+1) cnt = [0] * (N+1) now = 0 i = 1 while(flag[i] == 0 and K > now): flag[i] = 1 cnt[i] = now i = A[i-1] now += 1 if(K <= now): print(i) else: loop = now-cnt[i] kn = (K-now)%loop for j in range(kn): i = A[i-1] prin...
[["-", 0, 52, 15, 23, 0, 679, 12, 666, 667, 20], ["+", 0, 52, 15, 23, 0, 679, 12, 666, 667, 47], ["-", 0, 656, 0, 57, 15, 23, 0, 666, 667, 18], ["+", 0, 656, 0, 57, 15, 23, 0, 666, 667, 19]]
5
148
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, k; cin >> n >> k; vector<int64_t> as(n); for (auto &&a : as) { cin >> a; a--; } vector<int64_t> hs, ts; { set<int64_t> st; int64_t now = 0; while (true) { if (st.find(now) != st.end()) { vector<int64_...
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, k; cin >> n >> k; vector<int64_t> as(n); for (auto &&a : as) { cin >> a; a--; } vector<int64_t> hs, ts; { set<int64_t> st; int64_t now = 0; while (true) { if (st.find(now) != st.end()) { vector<int64_...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
266
def resolve(): N,K = map(int,input().split()) A = [int(i)-1 for i in input().split()] visited =[False]*N steps = [K for i in range(N)] current = 0 while True: if K == 0: return if not visited[current]: visited[current]=True steps[current]=K ...
def resolve(): N,K = map(int,input().split()) A = [int(i)-1 for i in input().split()] visited =[False]*N steps = [K for i in range(N)] current = 0 while True: if K == 0: print(current+1) return if not visited[current]: visited[current]=True ...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 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], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
145
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; for (int i = 0; i < n; ++i) --data[i]; vector<int> us...
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; for (int i = 0; i < n; ++i) --data[i]; vector<int> us...
[["-", 49, 50, 51, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["-", 0, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
219
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; typ...
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; typ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
1,445
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define pll pair<ll, ll> #define pb push_back #define mp(x, y) make_pair((x), (y)) #define F first #define S second #define I insert #define vll vector<ll> #define vbl vector<bool> #define vvll vector<vll> #define vld vector...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define pll pair<ll, ll> #define pb push_back #define mp(x, y) make_pair((x), (y)) #define F first #define S second #define I insert #define vll vector<ll> #define vbl vector<bool> #define vvll vector<vll> #define vld vector...
[["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22]]
1
691
n, k = map(int,input().split()) cities = list(map(lambda x:int(x)-1,input().split())) footprint_L = list() footprint_S = set() i = 0 footprint_S.add(i) footprint_L.append(i) while cities[i] not in footprint_S: footprint_S.add(cities[i]) footprint_L.append(cities[i]) i = cities[i] #print("terminal:", cit...
n, k = map(int,input().split()) cities = list(map(lambda x:int(x)-1,input().split())) footprint_L = list() footprint_S = set() i = 0 footprint_S.add(i) footprint_L.append(i) while cities[i] not in footprint_S: footprint_S.add(cities[i]) footprint_L.append(cities[i]) i = cities[i] #print("terminal:", cit...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
156
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; ll k; cin >> n >> k; vector<int> ar(n); for (int &i : ar) { cin >> i; i--; } int st = ar[0]; vector<int> lp; vector<bool> vis(n); vis[0] = 1; lp...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; ll k; cin >> n >> k; vector<int> ar(n); for (int &i : ar) { cin >> i; i--; } int st = ar[0]; vector<int> lp; vector<bool> vis(n); vis[0] = 1; lp...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
260
n, k = list(map(int, input().split())) arr = list(map(int, input().split())) visited_city = {1: 0} visited_city_inv = {0: 1} now = 1 num = 0 while True: next_city = arr[now - 1] num += 1 if next_city not in visited_city: visited_city[next_city] = num visited_city_inv[num] = next_city ...
n, k = list(map(int, input().split())) arr = list(map(int, input().split())) visited_city = {1: 0} visited_city_inv = {0: 1} now = 1 num = 0 while True: next_city = arr[now - 1] num += 1 if next_city not in visited_city: visited_city[next_city] = num visited_city_inv[num] = next_city ...
[["-", 64, 196, 0, 1, 0, 662, 12, 206, 51, 22], ["+", 64, 196, 0, 1, 0, 662, 12, 206, 51, 22]]
5
137
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; ll k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; vector<bool> vis(n + 1, false); vector<ll> vstep(n + 1); ll steps = 0; int i; ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; ll k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; vector<bool> vis(n + 1, false); vector<ll> vstep(n + 1); ll steps = 0; int i; ...
[["-", 8, 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
218
N, K = map(int, input().split()) A = list(map(int, input().split())) order = [-1]*N crr = 0 T = 0 s = -1 order[0] = 0 for i in range(N+1): crr = A[crr] - 1 if order[crr] >= 0: T = (i+1) - order[crr] s = order[crr] break order[crr] = i+1 if K <= s: crr = 0 while(K): K...
N, K = map(int, input().split()) A = list(map(int, input().split())) order = [-1]*N crr = 0 T = 0 s = -1 order[0] = 0 for i in range(N+1): crr = A[crr] - 1 if order[crr] >= 0: T = (i+1) - order[crr] s = order[crr] break order[crr] = i+1 if K <= s: crr = 0 while(K): K...
[["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
172
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<ll> towns; towns.push_back(1); vector<bool> visited(n + 1); visited[1] = true; while (1) { ll cur = towns[(int...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<ll> towns; towns.push_back(1); vector<bool> visited(n + 1); visited[1] = true; while (1) { ll cur = towns[(int...
[["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22]]
1
250
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int N; long long K; int A[200000]; signed main() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; A[i]--; } vector<int> distance(200000, INF); distance[0] = 0; int current = 0; int d = 0; for (int i = 0; i < N; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int N; long long K; int A[200000]; signed main() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; A[i]--; } vector<int> distance(200000, INF); distance[0] = 0; int current = 0; int d = 0; for (int i = 0; i < N; ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
212
#include <bits/stdc++.h> using namespace std; const int mn = 2e5 + 7; int a[mn], n, vis[mn]; vector<int> to; long long k; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", a + i); int s = 1, cnt = 0; while (!vis[s]) cnt++, to.push_back(s), vis[s] = cnt, s = a[s]; int lp ...
#include <bits/stdc++.h> using namespace std; const int mn = 2e5 + 7; int a[mn], n, vis[mn]; vector<int> to; long long k; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", a + i); int s = 1, cnt = 0; while (!vis[s]) cnt++, to.push_back(s), vis[s] = cnt, s = a[s]; int lp ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
186
# -*- coding: utf-8 -*- N,K = map(int, input().split()) A = [0]+list(map(int, input().split())) town_list = [-1,0]+[-1 for i in range(N-1)] town_now = 1 n_teleport = 0 while n_teleport<N: n_teleport += 1 town_now = A[town_now] if town_list[town_now]==-1: town_list[town_now] = n_teleport else: break ...
# -*- coding: utf-8 -*- N,K = map(int, input().split()) A = [0]+list(map(int, input().split())) town_list = [-1,0]+[-1 for i in range(N-1)] town_now = 1 n_teleport = 0 while n_teleport<K: n_teleport += 1 town_now = A[town_now] if town_list[town_now]==-1: town_list[town_now] = n_teleport else: break ...
[["-", 36, 36, 0, 656, 0, 52, 15, 666, 0, 22], ["+", 36, 36, 0, 656, 0, 52, 15, 666, 0, 22], ["-", 36, 36, 0, 656, 0, 57, 15, 666, 0, 22], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 0, 22]]
5
153
// Problem : D - Teleporter // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; vector<long> a, dep...
// Problem : D - Teleporter // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; vector<long> a, dep...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
241
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define rep(i, n) for (ll i = 0; i < (int)(n); i++) #define REP(i, m, n) for (ll i = m; i < (int)(n); i++) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, ...
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define rep(i, n) for (ll i = 0; i < (int)(n); i++) #define REP(i, m, n) for (ll i = m; i < (int)(n); i++) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
389
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define REP(i, k, n) for (long long i = (long long)(k); i < (long long)(n); i++) #define all(a) (a).begin(), (a).end() #define pb push_back #define PQ(T) priority_queue<T> #define PQS(T) priority_queue<T, vect...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define REP(i, k, n) for (long long i = (long long)(k); i < (long long)(n); i++) #define all(a) (a).begin(), (a).end() #define pb push_back #define PQ(T) priority_queue<T> #define PQS(T) priority_queue<T, vect...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 31, 22], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 22], ["+", 31, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
1
499
n,k=map(int,input().split()) a=list(map(int,input().split())) c=0 d={} d[1]=0 dd={} d[0]=1 now=1 while True: now=a[now-1] c+=1 if now in d: break d[now]=c dd[c]=now s=d[now] if k<=s: print(dd[k]) exit() p=c-s k-=s k%=p k+=s print(dd[k])
n,k=map(int,input().split()) a=list(map(int,input().split())) c=0 d={} d[1]=0 dd={} dd[0]=1 now=1 while True: now=a[now-1] c+=1 if now in d: break d[now]=c dd[c]=now s=d[now] if k<=s: print(dd[k]) exit() p=c-s k-=s k%=p k+=s print(dd[k])
[["-", 0, 656, 0, 1, 0, 662, 31, 206, 51, 22], ["+", 0, 656, 0, 1, 0, 662, 31, 206, 51, 22]]
5
133
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; ll k; scanf("%d %lld", &n, &k); vector<int> a(n), arrv; set<int> arr; for (int i = 0; i < n; i++) { int t; scanf("%d", &t); a[i] = --t; } int nc = 0; do { arr.insert(nc); arrv.push_back(nc); ...
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; ll k; scanf("%d %lld", &n, &k); vector<int> a(n), arrv; set<int> arr; for (int i = 0; i < n; i++) { int t; scanf("%d", &t); a[i] = --t; } int nc = 0; do { arr.insert(nc); arrv.push_back(nc); ...
[["+", 64, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 64, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
226
#include <bits/stdc++.h> using namespace std; #define LL long long //#define LL __int64 typedef pair<int, int> pii; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = ge...
#include <bits/stdc++.h> using namespace std; #define LL long long //#define LL __int64 typedef pair<int, int> pii; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = ge...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
1,127
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define ll long long #define ld long double #define ull unsigned long long using namespac...
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define ll long long #define ld long double #define ull unsigned long long using namespac...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
290
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep2(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() c...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep2(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() c...
[["-", 0, 52, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 17, 47], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 12, 13]]
1
247
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define fi first #define se second #define pb push_back #define forn(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define forr(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() const int MAXN = ...
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define fi first #define se second #define pb push_back #define forn(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define forr(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() const int MAXN = ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
338
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd n,k=map(int,input().split()) l=list(map(int,input().split())) a=1 s=set() count=0 while a not in s: s.add(a) a=l[a-1] count+=1 if count==k: print(a) exit() if count<k: k-=count # print(k) else: a=1 for i i...
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd n,k=map(int,input().split()) l=list(map(int,input().split())) a=1 s=set() count=0 while a not in s: s.add(a) a=l[a-1] count+=1 if count==k: print(a) exit() if count<k: k-=count # print(k) else: a=1 for i i...
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 612], ["-", 64, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["-", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
225
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") from collections import defaultdict class Graph(object): def __init__(self, N): self.N = N self.E = defaultdict(list) def add_edge(self, f, t, w=1): self.E[f].append((t, w)) def main(): N, K = ma...
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") from collections import defaultdict class Graph(object): def __init__(self, N): self.N = N self.E = defaultdict(list) def add_edge(self, f, t, w=1): self.E[f].append((t, w)) def main(): N, K = ma...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
265
#include <algorithm> #include <cstdlib> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, n) for (long int i = 0; i < n; i++) int main() { long int n, k; cin >> n >> k; long int a[n]; rep(i, n) { cin >> a[i]; a[i]--; } long int per[n]; ...
#include <algorithm> #include <cstdlib> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, n) for (long int i = 0; i < n; i++) int main() { long int n, k; cin >> n >> k; long int a[n]; rep(i, n) { cin >> a[i]; a[i]--; } long int per[n]; ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
217
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() using in = int64_t; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes c...
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() using in = int64_t; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes ...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
343
#include <bits/stdc++.h> #define two(a) (1 << (a)) #define LINF (1ll << 61) #define EPS (1e-14) #define Lshift(a, b) ((a) << (b)) #define Rshift(a, b) ((a) >> (b)) #define rep(a, b) for (a = 0; a < b; a++) #define xrep(a, b, c) for (a = b; a < c; a++) #define INF (1 << 29) #define sz(a) int(a.size()) #define mset(x) me...
#include <bits/stdc++.h> #define two(a) (1 << (a)) #define LINF (1ll << 61) #define EPS (1e-14) #define Lshift(a, b) ((a) << (b)) #define Rshift(a, b) ((a) >> (b)) #define rep(a, b) for (a = 0; a < b; a++) #define xrep(a, b, c) for (a = b; a < c; a++) #define INF (1 << 29) #define sz(a) int(a.size()) #define mset(x) me...
[["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 0, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 0, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 0, 9, 0, 57, 64, 9, 0, 37, 0, 13]]
1
322
#include <bits/stdc++.h> using namespace std; #define jaldi ios_base::sync_with_stdio(false) #define si(x) scanf("%d", &x) #define sl(x) scanf("%ld", &x) #define sll(x) scanf("%lld", &x) #define sc(x) scanf("%c", &x) #define ss(x) scanf("%s", x) #define pi(x) printf("%d", x) #define pl(x) printf("%ld", x) #define pll(...
#include <bits/stdc++.h> using namespace std; #define jaldi ios_base::sync_with_stdio(false) #define si(x) scanf("%d", &x) #define sl(x) scanf("%ld", &x) #define sll(x) scanf("%lld", &x) #define sc(x) scanf("%c", &x) #define ss(x) scanf("%s", x) #define pi(x) printf("%d", x) #define pl(x) printf("%ld", x) #define pll(...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
600
#include <algorithm> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long ...
#include <algorithm> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long ...
[["-", 0, 52, 15, 339, 51, 16, 31, 91, 17, 111], ["-", 0, 52, 15, 339, 51, 16, 31, 91, 28, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98]]
1
403
#include <bits/stdc++.h> #define ll long long using namespace std; inline char ch() { static char s[1 << 16], *S, *T; return (S == T) ? (T = (S = s) + fread(s, 1, 1 << 16, stdin), *S++) : *S++; } #define ch() getchar() template <typename T> void read(T &x) { x = 0; int f(1); char c = ch(); for (; !isdigit(c...
#include <bits/stdc++.h> #define ll long long using namespace std; inline char ch() { static char s[1 << 16], *S, *T; return (S == T) ? (T = (S = s) + fread(s, 1, 1 << 16, stdin), *S++) : *S++; } #define ch() getchar() template <typename T> void read(T &x) { x = 0; int f(1); char c = ch(); for (; !isdigit(c...
[["-", 64, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["+", 64, 1, 0, 2, 3, 4, 0, 69, 28, 22]]
1
399
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include ...
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
827
#include <stdio.h> int main() { long long int n, k; scanf("%lld %lld", &n, &k); long long int i; int a[200005]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } int b[200005]; long long int l; int v[200005]; for (i = 0; i < n; i++) v[i] = 0; b[0] = 0; v[0] = 1; l = 1; int ...
#include <stdio.h> int main() { long long int n, k; scanf("%lld %lld", &n, &k); long long int i; int a[200005]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } int b[200005]; long long int l; int v[200005]; for (i = 0; i < n; i++) v[i] = 0; b[0] = 0; v[0] = 1; l = 1; int ...
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47]]
0
255
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef long long ll; const ll MOD = 1e9 + 7; const long long INF = 1LL << 60; const double PI = 3.14159265358979323846; const int NMAX = 100005; using namespace std; int main()...
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef long long ll; const ll MOD = 1e9 + 7; const long long INF = 1LL << 60; const double PI = 3.14159265358979323846; const int NMAX = 100005; using namespace std; int main()...
[["-", 0, 11, 12, 69, 341, 342, 0, 16, 31, 22], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 11, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
283
#include <bits/stdc++.h> #define fo(i, a, b) for ((i) = (a); i <= (b); i++) #define rfo(i, a, b) for ((i) = (a); i >= (b); i--) #define inrange(x, y, z) (((x) >= (y)) && ((x) <= (z))) #define ALL(vec) ((vec).begin(), (vec).end()) #define SOR(vec) sort(ALL(vec)) #define UNI(vec) (vec).erase(unique(ALL(vec)), (vec).end()...
#include <bits/stdc++.h> #define fo(i, a, b) for ((i) = (a); i <= (b); i++) #define rfo(i, a, b) for ((i) = (a); i >= (b); i--) #define inrange(x, y, z) (((x) >= (y)) && ((x) <= (z))) #define ALL(vec) ((vec).begin(), (vec).end()) #define SOR(vec) sort(ALL(vec)) #define UNI(vec) (vec).erase(unique(ALL(vec)), (vec).end()...
[["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 109], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 22]]
1
357
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long ...
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
362
n,k = map(int,input().split()) a = list(map(int,input().split())) l = [1] al = [0 for i in range(n+1)] al[1] = 1 now = 1 for i in range(n): nex = a[now-1] if al[nex] == 0: l.append(nex) now = nex al[nex] += 1 if i == n-1: goal = nex else: goal = nex ...
n,k = map(int,input().split()) a = list(map(int,input().split())) l = [1] al = [0 for i in range(n+1)] al[1] = 1 now = 1 for i in range(n): nex = a[now-1] if al[nex] == 0: l.append(nex) now = nex al[nex] += 1 if i == n-1: goal = nex else: goal = nex ...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["-", 0, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
208
//#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <vecto...
//#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <vecto...
[["+", 8, 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, 18], ["+", 0, 52, 15, 339, 51, 16, 12, 16, 12, 22]]
1
995
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace __gnu_pbds; using namespace std; #d...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace __gnu_pbds; using namespace std; #d...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
345
#include <bits/stdc++.h> #define ll long long #define pb push_back #define ppb pop_back #define endl '\n' #define mii map<ll int, ll int> #define msi map<string, ll int> #define mis map<ll int, string> #define rep(i, a, b) for (ll int i = a; i < b; i++) #define repp(i, a, b) for (ll int i = b - 1; i >= a; i--) #define ...
#include <bits/stdc++.h> #define ll long long #define pb push_back #define ppb pop_back #define endl '\n' #define mii map<ll int, ll int> #define msi map<string, ll int> #define mis map<ll int, string> #define rep(i, a, b) for (ll int i = a; i < b; i++) #define repp(i, a, b) for (ll int i = b - 1; i >= a; i--) #define ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
375
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define pb push_back #define pii pair<int, int> #define F first #define S second #define mp make_pair using namespace std; const int N = 2e5 + 5; int n, x[N], ans; ll m; bool vis[N]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin ...
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define pb push_back #define pii pair<int, int> #define F first #define S second #define mp make_pair using namespace std; const int N = 2e5 + 5; int n, x[N], ans; ll m; bool vis[N]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin ...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
235
#include <algorithm> #include <cassert> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long l...
#include <algorithm> #include <cassert> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long l...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46]]
1
304
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; ll N, K; int A[200000]; bool used[200000]; int cnt[200000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fi...
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; ll N, K; int A[200000]; bool used[200000]; int cnt[200000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fi...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
264
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE'] def inpf() a=gets.chomp.split(" ").map(&:to_f)end def inps() a=gets.chomp.split(" ")end def copy(a) Marshal.load(Marshal.dump(a)) end def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r}...
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE'] def inpf() a=gets.chomp.split(" ").map(&:to_f)end def inps() a=gets.chomp.split(" ")end def copy(a) Marshal.load(Marshal.dump(a)) end def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r}...
[["-", 3, 4, 0, 742, 0, 738, 31, 739, 0, 24], ["-", 3, 4, 0, 742, 0, 738, 31, 739, 0, 25]]
4
364
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f[200009], i, j, zx, xc, pas, bo[200009]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> a >> b; for (i = 1; i <= a; i++) cin >> f[i]; i = 1; j = 1; bo[i] = 1; while (1) { if (j == b) { cou...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f[200009], i, j, zx, xc, pas, bo[200009]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> a >> b; for (i = 1; i <= a; i++) cin >> f[i]; i = 1; j = 1; bo[i] = 1; while (1) { if (j == b + 1) { ...
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
226
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author cherrypi59 */ #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FFOR(i, a, b) FOR(i, a, b + 1) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FOR(i, 1, n + 1) #define ALL(v) (v).b...
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author cherrypi59 */ #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FFOR(i, a, b) FOR(i, a, b + 1) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FOR(i, 1, n + 1) #define ALL(v) (v).b...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
500
#include <bits/stdc++.h> #include <unistd.h> //#include <ext/pb_ds/assoc_container.hpp> // Common file //#include <ext/pb_ds/tree_policy.hpp> // Including //seg_tree_order_statistics_node_update #include <cassert> #include <stdio.h> using namespace std; // using namespace __gnu_pbds; typedef long long lo; typedef long ...
#include <bits/stdc++.h> #include <unistd.h> //#include <ext/pb_ds/assoc_container.hpp> // Common file //#include <ext/pb_ds/tree_policy.hpp> // Including //seg_tree_order_statistics_node_update #include <cassert> #include <stdio.h> using namespace std; // using namespace __gnu_pbds; typedef long long lo; typedef long ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
1,434
from collections import defaultdict as dd N,K=map(int,input().split()) a = list(map(int,input().split())) res = 1 dic=dd(int) now = 1 mita = set() mita.add(now) dic[now] = 1 start = 0 end = 0 # loop while 1: next_town = a[now-1] # print(next_town) if next_town in mita: start = next_town ...
from collections import defaultdict as dd N,K=map(int,input().split()) a = list(map(int,input().split())) res = 1 dic=dd(int) now = 1 mita = set() mita.add(now) dic[now] = 1 start = 0 end = 0 # loop while 1: next_town = a[now-1] # print(next_town) if next_town in mita: start = next_town ...
[["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612]]
5
181
#include <algorithm> // minmax, sort, swap #include <bitset> #include <cassert> #include <cmath> #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr #include <map> ...
#include <algorithm> // minmax, sort, swap #include <bitset> #include <cassert> #include <cmath> #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr #include <map> ...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
277
#include <bits/stdc++.h> using namespace std; #define MOD (1000000000 + 7) #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define all(x) x.begin(), x.end() #define print(vec, l, r) \ for (int i = l; i <= r; i++) ...
#include <bits/stdc++.h> using namespace std; #define MOD (1000000000 + 7) #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define all(x) x.begin(), x.end() #define print(vec, l, r) \ for (int i = l; i <= r; i++) ...
[["-", 0, 14, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 7, 10, 43, 39, 78], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
346
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #in...
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #in...
[["-", 0, 30, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
262
#include <bits/stdc++.h> #define _USE_MATH_DEFINES #include <algorithm> #include <math.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define acc(v) accumulate(v.begin(), v.end(), 0) using namespace std; typedef long long ll; const int INF = 1e...
#include <bits/stdc++.h> #define _USE_MATH_DEFINES #include <algorithm> #include <math.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define acc(v) accumulate(v.begin(), v.end(), 0) using namespace std; typedef long long ll; const int INF = 1e...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
255
n,k = map(int,input().split()) al = list(map(int,input().split())) ansl = [] used = [0 for i in range(n)] now = 0 while True: if used[now] == 1: break ansl.append(now) used[now] = 1 now = al[now] -1 l = len(ansl) last = ansl.index(now) loop = ansl[last:] if k < len(ansl): print(ansl[k]) ...
n,k = map(int,input().split()) al = list(map(int,input().split())) ansl = [] used = [0 for i in range(n+1)] now = 0 while True: if used[now] == 1: break ansl.append(now) used[now] = 1 now = al[now] - 1 l = len(ansl) last = ansl.index(now) loop = ansl[last:] if k < len(ansl): print(ansl[k...
[["+", 0, 659, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
142
#include <bits/stdc++.h> #define N 200050 #define int long long #define pb push_back #define x first #define y second #define all(v) v.begin(), v.end() #define coffee prince #define sz(a) (int)a.size() using namespace std; int n, ar[N], k; int pr[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
#include <bits/stdc++.h> #define N 200050 #define int long long #define pb push_back #define x first #define y second #define all(v) v.begin(), v.end() #define coffee prince #define sz(a) (int)a.size() using namespace std; int n, ar[N], k; int pr[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
[["+", 64, 9, 0, 1, 0, 16, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 12, 13]]
1
247
#include <bits/stdc++.h> #define fi first #define se second #define U unsigned #define P std::pair<int, int> #define LL long long #define pb push_back #define MP std::make_pair #define all(x) x.begin(), x.end() #define CLR(i, a) memset(i, a, sizeof(i)) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define ROF(i, a...
#include <bits/stdc++.h> #define fi first #define se second #define U unsigned #define P std::pair<int, int> #define LL long long #define pb push_back #define MP std::make_pair #define all(x) x.begin(), x.end() #define CLR(i, a) memset(i, a, sizeof(i)) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define ROF(i, a...
[["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 22], ["+", 0, 2, 3, 4, 0, 69, 341, 342, 0, 22]]
1
322
n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]-=1 #print(a) ever=[False]*n ever[0]=True now=0 saisho=[0] for i in range(n): now=a[now] if(not ever[now]): saisho.append(now) ever[now]=True else: break #print(saisho) roop=[] roop.appen...
n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]-=1 #print(a) ever=[False]*n ever[0]=True now=0 saisho=[0] for i in range(n): now=a[now] if(not ever[now]): saisho.append(now) ever[now]=True else: break #print(saisho) roop=[] roop.appen...
[["-", 3, 4, 0, 657, 31, 206, 206, 657, 17, 72], ["-", 3, 4, 0, 657, 31, 206, 206, 657, 12, 612]]
5
214
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (n); ++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define vi vector<int> #d...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (n); ++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define vi vector<int> #d...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
541
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define pb push_back #define eb emplace_back #define INF LLONG_MAX #define PI 3.14159265359 #define sz(c) (int)c.size() #define len(c) (int)c.length() #define hcf(a, b) __...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define pb push_back #define eb emplace_back #define INF LLONG_MAX #define PI 3.14159265359 #define sz(c) (int)c.size() #define len(c) (int)c.length() #define hcf(a, b) __...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
370
#include <bits/stdc++.h> using namespace std; //#pragma gcc optimize("O3,unroll-loop") //#pragma gcc //target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native") //#define int long long //#define double long double signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, arr[200001]...
#include <bits/stdc++.h> using namespace std; //#pragma gcc optimize("O3,unroll-loop") //#pragma gcc //target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native") //#define int long long //#define double long double signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, arr[200001]...
[["-", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
202
// Problem : D - Teleporter // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <cstring> #include <iostream> using namespace std; int a[2...
// Problem : D - Teleporter // Contest : AtCoder - AtCoder Beginner Contest 167 // URL : https://atcoder.jp/contests/abc167/tasks/abc167_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <cstring> #include <iostream> using namespace std; int a[2...
[["+", 8, 9, 0, 7, 8, 9, 0, 57, 0, 121], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 25]]
1
174
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace ...
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace ...
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73]]
1
616
#include <bits/stdc++.h> using namespace std; const auto start_time = std::chrono::high_resolution_clock::now(); void timecalculater() { #ifndef ONLINE_JUDGE auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time - start_time; cerr << "Time Taken : " << diff.count...
#include <bits/stdc++.h> using namespace std; const auto start_time = std::chrono::high_resolution_clock::now(); void timecalculater() { #ifndef ONLINE_JUDGE auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time - start_time; cerr << "Time Taken : " << diff.count...
[["+", 75, 76, 0, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 57, 75, 76, 0, 9, 0, 43, 0, 35], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32]]
1
862
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define vi vector<ll> #define vvi vector<vi> #define BITLE(n) (1LL << ((ll)n)) #define SHIFT_LEFT(n) (1LL << ((ll)n)) #define SUBS(s, f, t) (...
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define vi vector<ll> #define vvi vector<vi> #define BITLE(n) (1LL << ((ll)n)) #define SHIFT_LEFT(n) (1LL << ((ll)n)) #define SUBS(s, f, t) (...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
256
#include "bits/stdc++.h" #define hhh cerr << "hhh" << endl #define see(x) cerr << (#x) << '=' << (x) << endl using namespace std; typedef long long ll; typedef pair<int, int> pr; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') ...
#include "bits/stdc++.h" #define hhh cerr << "hhh" << endl #define see(x) cerr << (#x) << '=' << (x) << endl using namespace std; typedef long long ll; typedef pair<int, int> pr; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') ...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
395