This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
using namespace std;
const int mx = 1e6 + 15;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
vector<ll> freq(n+1);
a[0]=-1;
for (int i=1;i<n;i++){
cin >> a[i];
a[i]--;
}
for (int i=n-1; i>=1;i--){
freq[i+1]++;
int cur = a[i];
int cnt = 1;
//cout << cur+1 << ' ';
while (cur!=-1){
freq[cur]+=++cnt;
cur = a[cur];
//cout << cur+1 << ' ';
}
}
freq[0]++;
freq[1]++;
// idk why
for (int i=0;i<n;i++){
cout << freq[i] << ' ';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |