Submission #241843

#TimeUsernameProblemLanguageResultExecution timeMemory
241843matheo_apdBirokracija (COCI18_birokracija)C++17
70 / 100
170 ms15608 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define maxn 200005 #define siz first #define sum second vector<int> adj[maxn]; int sz_dp[maxn], sum_dp[maxn]; int n; void dfs(int v){ if(adj[v].size() == 0){ sz_dp[v] = sum_dp[v] = 1; return; } for(int i = 0; i < adj[v].size(); i++){ int u = adj[v][i]; dfs(u); sz_dp[v] += sz_dp[u]; sum_dp[v] += sum_dp[u]; } sz_dp[v]++; sum_dp[v] += sz_dp[v]; } int main(){ memset(sum_dp, 0, sizeof sum_dp); memset(sz_dp, 0, sizeof sz_dp); cin >> n; for(int i = 2; i <= n; i++){ int x; cin >> x; if(i == 1) continue; adj[x].push_back(i); } dfs(1); for(int i = 1; i <= n; i++) cout << sum_dp[i] << " "; cout << endl; return 0; }

Compilation message (stderr)

birokracija.cpp: In function 'void dfs(int)':
birokracija.cpp:21:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[v].size(); i++){
                    ~~^~~~~~~~~~~~~~~
#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...