# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168319 | ArKCa | Birokracija (COCI18_birokracija) | C++17 | 114 ms | 27088 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 ll long long
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define f1 first
#define s2 second
#define N 200005
#define ekle 200
using namespace std;
vector<ll>v[N];
ll ata[N],cocuk[N],deger[N];
ll n;
void atam(ll x,ll dgr){
if(x==-1)return;
deger[x]+=dgr;
atam(ata[x],dgr+1);
}
pair<ll,ll> dfs(ll x){
pair<ll,ll>sa,as;
for(ll i=0;i<v[x].size();i++){
as=dfs(v[x][i]);
sa.f1+=as.f1;
sa.s2+=as.s2;
}
deger[x]=sa.f1+sa.s2;
deger[x]++;
return {deger[x],sa.s2+1};
}
int main(){
// freopen("a.gir","r",stdin);
// freopen("a.cik","w",stdout);
scanf("%lld",&n);
ata[1]=-1;
for(ll i=2;i<=n;i++){
scanf("%lld",&ata[i]);
v[ata[i]].pb(i);
}
dfs(1);
for(ll i=1;i<=n;i++){
printf("%lld ",deger[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... |