Submission #992529

#TimeUsernameProblemLanguageResultExecution timeMemory
992529Uniq0rnBirokracija (COCI18_birokracija)C++17
70 / 100
44 ms16840 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...