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>
using namespace std;
#define endl "\n"
int n;
int arr[(int)1e5];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--){
cin >> n;
map<int,deque<int> >mp;
for(int i = 2;i<=n;i++){
int x;
cin >> x;
mp[x].push_front(i);
}
while(mp[1].size() > 0){
int x = 1;
int tot = 0;
while(mp[x].size() > 0){
tot++;
x = mp[x].back();
}
tot++;
x = 1;
int y = 0;
while(mp[x].size() > 0){
arr[x] += tot--;
y = x;
x = mp[x].back();
}
arr[x]++;
mp[y].pop_back();
}
arr[1]++;
for(int i = 1;i<=n;i++){
cout << arr[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... |