Submission #85736

#TimeUsernameProblemLanguageResultExecution timeMemory
85736heonBirokracija (COCI18_birokracija)C++11
70 / 100
359 ms36084 KiB
#include<bits/stdc++.h> using namespace std; vector <int> g[200005]; map <int,int> mp; int dfs(int x, int parent){ int res = 1; for(auto y : g[x]){ res += dfs(y, x); } mp[x] += res; if(x != 1) mp[parent] += mp[x]; return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for(int i = 2; i <= n; i++){ int x; cin >> x; g[x].push_back(i); //g[i].push_back(x); } dfs(1, -1); for(int i = 1; i <= n; i++) cout << mp[i] << " "; }
#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...