# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50093 | luciocf | Birokracija (COCI18_birokracija) | C++14 | 259 ms | 32736 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>
using namespace std;
const int MAXN = 2e5+10;
typedef long long ll;
int n;
ll ans[MAXN], size[MAXN];
vector<int> grafo[MAXN];
void get_size(int u, int p)
{
for (int i = 0; i < grafo[u].size(); i++)
{
int v = grafo[u][i];
if (v == p) continue;
get_size(v, u);
size[u] += size[v];
}
size[u]++;
}
void DFS(int u, int p)
{
for (int i = 0; i < grafo[u].size(); i++)
{
int v = grafo[u][i];
if (v == p) continue;
DFS(v, u);
ans[u] += (size[v]+ans[v]);
}
ans[u]++;
}
int main(void)
{
cin >> n;
for (int i = 2; i <= n; i++)
{
int x;
cin >> x;
grafo[x].push_back(i);
grafo[i].push_back(x);
}
get_size(1, -1);
DFS(1, -1);
cout << ans[1];
for (int i = 2; i <= n; i++)
cout << " " << ans[i];
cout << "\n";
}
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... |