# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
986424 | 2024-05-20T13:39:38 Z | kh0i | Birokracija (COCI18_birokracija) | C++17 | 63 ms | 26964 KB |
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using ll = long long; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll> (l, r)(rng); } const int N = 2e5 + 3; int n; vector<int> g[N]; ll f[N], sz[N]; void dfs_sz(int u){ sz[u] = 1; for(int v : g[u]){ dfs_sz(v); sz[u] += sz[v]; } } void dfs(int u){ for(int v : g[u]){ dfs(v); f[u] += f[v]; } f[u] += sz[u]; } void solve(){ cin >> n; for(int i = 2; i <= n; ++i){ int p; cin >> p; g[p].push_back(i); } dfs_sz(1); dfs(1); for(int i = 1; i <= n; ++i) cout << f[i] << ' '; } int32_t main() { cin.tie(nullptr)->sync_with_stdio(0); #define task "troll" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; // cin >> test; for(int i = 1; i <= test; ++i){ // cout << "Case #" << i << ": "; solve(); } #ifdef LOCAL cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; #endif return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5980 KB | Output is correct |
2 | Correct | 2 ms | 5980 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5980 KB | Output is correct |
2 | Correct | 2 ms | 5980 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5980 KB | Output is correct |
2 | Correct | 2 ms | 6232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 6748 KB | Output is correct |
2 | Correct | 7 ms | 8888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 9820 KB | Output is correct |
2 | Correct | 19 ms | 10328 KB | Output is correct |
3 | Correct | 16 ms | 11192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 12856 KB | Output is correct |
2 | Correct | 39 ms | 15452 KB | Output is correct |
3 | Correct | 43 ms | 26964 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 12936 KB | Output is correct |
2 | Correct | 42 ms | 14500 KB | Output is correct |
3 | Correct | 39 ms | 16508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 12880 KB | Output is correct |
2 | Correct | 43 ms | 14628 KB | Output is correct |
3 | Correct | 42 ms | 18464 KB | Output is correct |