# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42856 | iletavcioski | Birokracija (COCI18_birokracija) | C++14 | 101 ms | 28864 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 <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;
vector<vector<int> > v;
ll dp[200002];
ll dp_1[200002];
void dfs(int x)
{
ll brojac=1;
for(int i=0;i<v[x].size();i++)
{
dfs(v[x][i]);
dp_1[x]+=dp_1[v[x][i]];
dp[x]+=dp[v[x][i]];
}
dp_1[x]++;
dp[x]+=dp_1[x];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int n;
cin>>n;
vector<int> vec;
v.insert(v.begin(),n+1,vec);
for(int i=1;i<n;i++)
{
int a;
cin>>a;
a--;
v[a].push_back(i);
}
for(int i=0;i<n;i++)
sort(v[i].begin(),v[i].end());
dfs(0);
for(int i=0;i<n;i++)
{
if(i)
cout<<" ";
cout<<dp[i];
}
cout<<endl;
return 0;
}
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... |