Submission #42856

#TimeUsernameProblemLanguageResultExecution timeMemory
42856iletavcioskiBirokracija (COCI18_birokracija)C++14
100 / 100
101 ms28864 KiB
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> #include <cmath> using namespace std; typedef long long ll; vector<vector<int> > v; ll dp[200002]; ll dp_1[200002]; void dfs(int x) { ll brojac=1; for(int i=0;i<v[x].size();i++) { dfs(v[x][i]); dp_1[x]+=dp_1[v[x][i]]; dp[x]+=dp[v[x][i]]; } dp_1[x]++; dp[x]+=dp_1[x]; } int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int n; cin>>n; vector<int> vec; v.insert(v.begin(),n+1,vec); for(int i=1;i<n;i++) { int a; cin>>a; a--; v[a].push_back(i); } for(int i=0;i<n;i++) sort(v[i].begin(),v[i].end()); dfs(0); for(int i=0;i<n;i++) { if(i) cout<<" "; cout<<dp[i]; } cout<<endl; return 0; }

Compilation message (stderr)

birokracija.cpp: In function 'void dfs(int)':
birokracija.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                  ^
birokracija.cpp:14:8: warning: unused variable 'brojac' [-Wunused-variable]
     ll brojac=1;
        ^
#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...