Submission #580350

#TimeUsernameProblemLanguageResultExecution timeMemory
580350MuntherCarrotBirokracija (COCI18_birokracija)C++14
100 / 100
72 ms17612 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define all(x) x.begin(),x.end() int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<vector<int>> vv(n+1); vector<ll> vec(n+1,0),f(n+1,0); for(int i=1;i<n;i++){ int num; cin >> num; vv[num].push_back(i+1); } for(int i=n; i>0; i--){ if(vv[i].size() == 0){vec[i]++;continue;} for(auto a : vv[i]){ f[i]+=f[a]+1; vec[i]+=vec[a]; } vec[i]+=f[i]+1; } for(int i=1;i<n+1;i++) cout << vec[i] << ' '; //cout << endl; //for(int i=1;i<n+1;i++) cout << vv[i].size() << ' '; 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...