# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127393 | impri | Birokracija (COCI18_birokracija) | C++14 | 255 ms | 27000 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;
int number;
vector<int>graph[200001];
int visited[200001];
int siz[200001];
long long money[200001];
int get_size(int n){
visited[n]=1;
int result=1;
for(int i=0;i<graph[n].size();i++){
if(!visited[graph[n][i]]){
result+=get_size(graph[n][i]);
}
}
return siz[n]=result;
}
long long get_m(int n){
long long result=1;
visited[n]=1;
for(int i=0;i<graph[n].size();i++){
if(!visited[graph[n][i]]){
result+=(get_m(graph[n][i])+siz[graph[n][i]]);
}
}
return money[n]=result;
}
int main() {
cin >> number;
for(int i=2;i<=number;i++){
int a;
cin >> a;
graph[i].push_back(a);
graph[a].push_back(i);
}
get_size(1);
memset(visited,0,sizeof(visited));
get_m(1);
for(int i=1;i<=number;i++){
cout << money[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... |