Submission #992529

# Submission time Handle Problem Language Result Execution time Memory
992529 2024-06-04T14:45:50 Z Uniq0rn Birokracija (COCI18_birokracija) C++17
70 / 100
44 ms 16840 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define pi pair<int,int>
#define sz(x) (int)x.size()

const int N = 2e5+10;
vector<int> adj[N],ans(N),cnt(N);
int n;
void dfs1(int u){
    cnt[u] = 1;
    for(auto v:adj[u]){
        dfs1(v);
        cnt[u] += cnt[v];
    }
}
void dfs2(int u){
    for(auto v:adj[u]){
        dfs2(v);
        ans[u] += ans[v];
    }
    ans[u] += cnt[u];
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<n;i++){
        int x;cin >> x;
        x--;
        adj[x].push_back(i);
    }
    /*
    for(int i=0;i<n;i++){
        cout << i << '\n';
        for(auto v:adj[i]) cout << v << ' ';
        cout << '\n';
    }
    */
    dfs1(0);
    dfs2(0);
    for(int i=0;i<n;i++){
        cout << ans[i] << ' ';
    }
    return 0;
}
# 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 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 2 ms 6488 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7004 KB Output is correct
2 Correct 6 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 8024 KB Output is correct
2 Correct 17 ms 8284 KB Output is correct
3 Correct 14 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 10576 KB Output is correct
2 Incorrect 34 ms 12884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 10220 KB Output is correct
2 Correct 37 ms 11868 KB Output is correct
3 Incorrect 34 ms 14428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 10064 KB Output is correct
2 Correct 38 ms 12184 KB Output is correct
3 Incorrect 34 ms 16840 KB Output isn't correct
4 Halted 0 ms 0 KB -