Submission #168319

# Submission time Handle Problem Language Result Execution time Memory
168319 2019-12-12T11:53:24 Z ArKCa Birokracija (COCI18_birokracija) C++17
100 / 100
114 ms 27088 KB
#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

birokracija.cpp: In function 'std::pair<long long int, long long int> dfs(long long int)':
birokracija.cpp:22:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i=0;i<v[x].size();i++){
                ~^~~~~~~~~~~~
birokracija.cpp: In function 'int main()':
birokracija.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
birokracija.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&ata[i]);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5756 KB Output is correct
2 Correct 15 ms 6136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 7672 KB Output is correct
2 Correct 31 ms 7928 KB Output is correct
3 Correct 32 ms 9336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12280 KB Output is correct
2 Correct 79 ms 14428 KB Output is correct
3 Correct 82 ms 27088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 12400 KB Output is correct
2 Correct 82 ms 13432 KB Output is correct
3 Correct 80 ms 16632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 12172 KB Output is correct
2 Correct 90 ms 13688 KB Output is correct
3 Correct 82 ms 18424 KB Output is correct