# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239564 | 2020-06-16T11:30:05 Z | MrRobot_28 | Birokracija (COCI18_birokracija) | C++17 | 201 ms | 33192 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 6 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 1920 KB | Output is correct |
2 | Correct | 21 ms | 2560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 67 ms | 6136 KB | Output is correct |
2 | Correct | 58 ms | 6392 KB | Output is correct |
3 | Correct | 50 ms | 7672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 201 ms | 16632 KB | Output is correct |
2 | Correct | 135 ms | 19192 KB | Output is correct |
3 | Correct | 145 ms | 33192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 167 ms | 16604 KB | Output is correct |
2 | Correct | 142 ms | 18040 KB | Output is correct |
3 | Correct | 142 ms | 20448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 194 ms | 16248 KB | Output is correct |
2 | Correct | 138 ms | 18300 KB | Output is correct |
3 | Correct | 135 ms | 22776 KB | Output is correct |