Submission #294565

#TimeUsernameProblemLanguageResultExecution timeMemory
2945657_7_7Birokracija (COCI18_birokracija)C++17
100 / 100
129 ms29524 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n; int sub[N]; long long cnt[N]; vector<int> g[N]; void dfs(int v, int p){ sub[v] = 1, cnt[v] = 1; for(auto to: g[v]){ if(to == p) continue; dfs(to, v); cnt[v] += cnt[to] + sub[to]; sub[v] += sub[to]; } } int main() { ios_base::sync_with_stdio(false); cin >> n; for(int i = 2; i <= n; i ++){ int x; cin >> x; g[x].push_back(i); g[i].push_back(x); } dfs(1, 1); for(int i = 1; i <= n; i ++){ cout << cnt[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...