Submission #113204

#TimeUsernameProblemLanguageResultExecution timeMemory
113204tutisBirokracija (COCI18_birokracija)C++17
100 / 100
114 ms24848 KiB
/*input 5 1 2 2 4 */ #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int>adj[202020]; ll ans[202020]; void dfs(int i, ll &sz, ll &ret) { sz = 1; ret = 0; for (int j : adj[i]) { ll x, y; dfs(j, x, y); sz += x; ret += y; } ret += sz; ans[i] = ret; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 2; i <= n; i++) { int p; cin >> p; adj[p].push_back(i); } ll x, y; dfs(1, x, y); for (int i = 1; i <= n; i++) cout << ans[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...