Submission #1018538

#TimeUsernameProblemLanguageResultExecution timeMemory
1018538vjudge1Birokracija (COCI18_birokracija)C++17
100 / 100
75 ms28756 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, p[N], sz[N]; long long dp[N]; vector<int> g[N]; void dfs(int v){ sz[v] = 1; for (int u : g[v]){ dfs(u); sz[v] += sz[u]; dp[v] += dp[u]; } dp[v] += sz[v]; } int main(){ cin >> n; for (int i = 2; i <= n; i ++){ cin >> p[i]; g[p[i]].push_back(i); } dfs(1); for (int i = 1; i <= n; i ++) cout << dp[i] << " "; cout << endl; }
#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...