# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168313 | aydinenes | Birokracija (COCI18_birokracija) | C++11 | 248 ms | 37596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define mid(l,r) ((l+r)/2)
using namespace std;
const int N = 1e6 + 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];
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |