# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580134 | emad234 | Birokracija (COCI18_birokracija) | C++17 | 1092 ms | 10700 KiB |
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 all(v) ((v).begin(),(v).end())
#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int mxN = 2e6 + 1;
vector<vector<int>>v;
vector<int>add;
int ans[mxN];
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >>n;
v.resize(n +1 );
for(int i = 2; i <= n;i++){
int x;cin>>x;
v[x].push_back(i);
}
while(v[1].size()){
add.clear();
int i = 1;
int j = 1;
int vali = 1;
int val = 1;
int cnt = 0;
int valj;
while(!v[vali].empty()){
cnt++;
valj = vali;
i = min_element(v[vali].begin(),v[vali].end()) - v[vali].begin();
val++;
vali = v[vali][i];
add.push_back(vali);
}
ans[1] += val;
for(int k = 0;k < add.size();k++){
ans[add[k]] += val - (k + 1);
}
v[valj].erase(v[valj].begin() + i);
}
ans[1]++;
for(int i = 1;i <= n;i++){
cout <<ans[i]<<' ';
}
}
Compilation message (stderr)
# | 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... |