Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 0 KBi |
#2 |
Correcto
|
0.004 s | 0 KBi |
#3 |
Correcto
|
0.004 s | 0 KBi |
#4 |
Correcto
|
0.004 s | 6 KBi |
#5 |
Correcto
|
0.004 s | 5 KBi |
#6 |
Correcto
|
0.145 s | 26 KBi |
#7 |
Correcto
|
0.187 s | 26 KBi |
#8 |
Correcto
|
0.004 s | 10 KBi |
#9 |
Correcto
|
0.004 s | 4 KBi |
#10 |
Correcto
|
0.003 s | 1 KBi |
#11 |
Correcto
|
0.006 s | 10 KBi |
#12 |
Correcto
|
0.012 s | 9 KBi |
#13 |
Correcto
|
0.018 s | 3 KBi |
#14 |
Correcto
|
0.013 s | 3 KBi |
#15 |
Correcto
|
0.018 s | 3 KBi |
#16 |
Correcto
|
0.013 s | 3 KBi |
#17 |
Correcto
|
0.006 s | 1 KBi |
#18 |
Correcto
|
0.004 s | 2 KBi |
#19 |
Correcto
|
0.006 s | 0 KBi |
#20 |
Correcto
|
0.004 s | 0 KBi |
#21 |
Correcto
|
0.268 s | 26 KBi |
#22 |
Correcto
|
0.494 s | 26 KBi |
#23 |
Correcto
|
0.655 s | 26 KBi |
#24 |
Correcto
|
0.135 s | 26 KBi |
#25 |
Correcto
|
0.548 s | 26 KBi |
/// Write by Daniel Perez .PERAPRO #include<bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define ff first #define ss second #define all(s) s.begin(), s.end() typedef long long ll; typedef unsigned long long ull; typedef long double ld; using vi=vector<int>; using vl=vector<ll>; using pii=pair<int,int>; char el = '\n'; char esp = ' '; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ostream& operator<<(ostream& os, const vector<int> &v){ for(auto const &i: v){ os<<i<<" "; } os<<'\n'; return os; } string yes="YES"; string no="NO"; const int Log2 = 62; const int N = 1e5+5; int lca[N][Log2]; int solve(int idx, ll R){ int ans = idx; for(int i = 0;R;R >>= 1, i++){ if(R & 1){ ans = lca[ans][i]; } } return ans; } int main(){ fast_io; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ ll n, R, child; cin>>n>>R; vi v(n); iota(all(v), 1); vi p(n); for(int i=0;i<n;i++){ cin>>child; lca[i][0] = child; } for(int j=0;j + 1 < Log2;j++){ for(int i=0;i<n;i++){ lca[i][j + 1] = lca[ lca[i][j] ][j]; } } vi ans(n); for(int i=0;i<n;i++){ ans[solve(i, R)] = v[i]; } for(int e:ans) cout<<e<<esp; } /* */