# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168311 | 2019-12-12T11:19:49 Z | aydinenes | Birokracija (COCI18_birokracija) | C++11 | 77 ms | 7544 KB |
#include<bits/stdc++.h> #define mid(l,r) ((l+r)/2) using namespace std; const int N = 1e5+7; const int inf=1e9+7; int n; int a[N]; vector<int> g[N]; int ans[N]; void dfsa(int node, int p){ ans[node] = 1; for(int i = 0; i < g[node].size(); i++){ int x = g[node][i]; if(x == p) continue; dfsa(x, node); ans[node] += ans[x]; } } void dfsb(int node, int p){ for(int i = 0; i < g[node].size(); i++){ int x = g[node][i]; if(x == p) continue; dfsb(x, node); ans[node] += ans[x]; } } int main(){ cin >> n; for(int i = 2; i <= n; i++) cin >> a[i]; for(int i = 2; i <= n; i++){ g[i].push_back(a[i]); g[a[i]].push_back(i); } dfsa(1, 0); dfsb(1, 0); for(int i=1; i <= n; i++){ cout << ans[i] << " "; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 3704 KB | Output is correct |
2 | Correct | 23 ms | 3960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 6048 KB | Output is correct |
2 | Correct | 61 ms | 6272 KB | Output is correct |
3 | Correct | 60 ms | 7544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 70 ms | 5844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 64 ms | 5368 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 77 ms | 6332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |