Submission #40396

#TimeUsernameProblemLanguageResultExecution timeMemory
40396szawinisBirokracija (COCI18_birokracija)C++14
100 / 100
182 ms30432 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5+1; int n, sz[N]; vector<int> g[N]; long long dp[N]; void dfs(int u) { sz[u] = 1; for(int v: g[u]) { dfs(v); dp[u] += dp[v]; sz[u] += sz[v]; } dp[u] += sz[u]; } int main() { scanf("%d", &n); for(int i = 2, p; i <= n; i++) { cin >> p; g[p].push_back(i); } dfs(1); for(int i = 1; i <= n; i++) printf("%lld ", dp[i]); }

Compilation message (stderr)

birokracija.cpp: In function 'int main()':
birokracija.cpp:18:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...