Submission #1006346

# Submission time Handle Problem Language Result Execution time Memory
1006346 2024-06-23T19:46:15 Z DangerNoodle7591 Birokracija (COCI18_birokracija) C++17
100 / 100
38 ms 26964 KB
#include  <bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define endl '\n'
#define int long long int
//#define ll long long
#define pb push_back
#define p push
#define f first
#define s second
#define N 200200
vector<int> adj[N];
int sz[N],deg[N];
int dfs(int x){
  sz[x]=0;
  for(auto u:adj[x])sz[x]+=dfs(u);
  for(auto u:adj[x]){
    deg[x]+=deg[u]+sz[u];
  }
  sz[x]++;
  deg[x]++;
  return sz[x];
}
signed main(){
  lalala;
  int n;cin>>n;
  for(int i=2;i<=n;i++){
    int a;cin>>a;
    adj[a].pb(i);
  }
  dfs(1);
  for(int i=1;i<=n;i++)cout<<deg[i]<<" ";
  cout<<endl;
 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 1 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 5 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 10076 KB Output is correct
2 Correct 14 ms 10256 KB Output is correct
3 Correct 12 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13412 KB Output is correct
2 Correct 31 ms 15576 KB Output is correct
3 Correct 34 ms 26964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 13396 KB Output is correct
2 Correct 36 ms 14676 KB Output is correct
3 Correct 32 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 13404 KB Output is correct
2 Correct 30 ms 14928 KB Output is correct
3 Correct 31 ms 18432 KB Output is correct