Submission #886871

# Submission time Handle Problem Language Result Execution time Memory
886871 2023-12-13T05:58:09 Z vjudge1 Birokracija (COCI18_birokracija) C++17
100 / 100
48 ms 23636 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=2e5+100;
#else
    const int lim=2e3+100;
#endif

#include "bits/stdc++.h"
using namespace std;

#define int int64_t
#define pb push_back

const int mod=1e9+7;
using pii=pair<int,int>;

vector<int>v[lim];
int ans[lim];

pii dfs(int node){
    int task=1,past=0;
    for(int j:v[node]){
        pii ret=dfs(j);
        task+=ret.first;
        past+=ret.second;
    }
    ans[node]=task+past;
    past++;
    return {ans[node],past};
}

inline void solve(){
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        int tem;
        cin>>tem;
        v[tem].pb(i);
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<" ";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    //freopen("boards.in","r",stdin);
    //freopen("boards.out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7004 KB Output is correct
2 Correct 6 ms 7348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8024 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 14 ms 9156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 11096 KB Output is correct
2 Correct 37 ms 12748 KB Output is correct
3 Correct 42 ms 23636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 10684 KB Output is correct
2 Correct 35 ms 11732 KB Output is correct
3 Correct 37 ms 13652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 10576 KB Output is correct
2 Correct 36 ms 11980 KB Output is correct
3 Correct 36 ms 15448 KB Output is correct