Submission #83138

#TimeUsernameProblemLanguageResultExecution timeMemory
83138Leonardo_PaesBirokracija (COCI18_birokracija)C++11
70 / 100
1071 ms11408 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 200100 vector<int> grafo[MAXN]; int resp[MAXN], pai[MAXN], mark[MAXN]; void dfs (int u, int num, int sum){ mark[u]=1; resp[u]+=sum; if(pai[u]==0)return; if(mark[pai[u]]==0){ num++; } dfs(pai[u], num, (sum+num)); } int main(){ int n; cin >> n; for(int i=2; i<=n; i++){ int p; cin >> p; grafo[p].push_back(i); pai[i]=p; } pai[1]=0; for(int i=2; i<=n; i++){ if(grafo[i].size() == 0){ dfs(i, 1, 1); } } for(int i=1; i<=n; i++){ cout << resp[i] << " "; } cout << endl; return 0; }
#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...