Submission #992527

# Submission time Handle Problem Language Result Execution time Memory
992527 2024-06-04T14:45:07 Z Uniq0rn Birokracija (COCI18_birokracija) C++17
70 / 100
40 ms 16720 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){
    ans[u] += cnt[u];
    for(auto v:adj[u]){
        dfs2(v);
        ans[u] += ans[v];
    }
}
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 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 6492 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 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 3 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7004 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8268 KB Output is correct
2 Correct 14 ms 8796 KB Output is correct
3 Correct 13 ms 9648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 11344 KB Output is correct
2 Incorrect 35 ms 13908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 11344 KB Output is correct
2 Correct 35 ms 13008 KB Output is correct
3 Incorrect 33 ms 14932 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 11348 KB Output is correct
2 Correct 35 ms 13140 KB Output is correct
3 Incorrect 35 ms 16720 KB Output isn't correct
4 Halted 0 ms 0 KB -