Submission #239564

#TimeUsernameProblemLanguageResultExecution timeMemory
239564MrRobot_28Birokracija (COCI18_birokracija)C++17
100 / 100
201 ms33192 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector <vector <int> > g; vector <int> ans; vector <int> sum, _size, h; void dfs(int v, int p = -1) { _size[v] = 1; sum[v] = 0; for(int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if(to != p) { h[to] = h[v] + 1; dfs(to, v); _size[v] += _size[to]; sum[v] += sum[to]; } } sum[v] += h[v] + 1; ans[v] = sum[v] - _size[v] * h[v]; } signed main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); // cout.tie(NULL); int n; cin >> n; g.resize(n); ans.resize(n); sum.resize(n); _size.resize(n); h.resize(n); for(int i = 1; i < n; i++) { int p; cin >> p; p--; g[p].push_back(i); } dfs(0, -1); for(int i = 0; i < n; i++) { cout << ans[i] << " "; } return 0; }

Compilation message (stderr)

birokracija.cpp: In function 'void dfs(long long int, long long int)':
birokracija.cpp:11:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[v].size(); 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...