Submission #127393

#TimeUsernameProblemLanguageResultExecution timeMemory
127393impriBirokracija (COCI18_birokracija)C++14
100 / 100
255 ms27000 KiB
#include<bits/stdc++.h> using namespace std; int number; vector<int>graph[200001]; int visited[200001]; int siz[200001]; long long money[200001]; int get_size(int n){ visited[n]=1; int result=1; for(int i=0;i<graph[n].size();i++){ if(!visited[graph[n][i]]){ result+=get_size(graph[n][i]); } } return siz[n]=result; } long long get_m(int n){ long long result=1; visited[n]=1; for(int i=0;i<graph[n].size();i++){ if(!visited[graph[n][i]]){ result+=(get_m(graph[n][i])+siz[graph[n][i]]); } } return money[n]=result; } int main() { cin >> number; for(int i=2;i<=number;i++){ int a; cin >> a; graph[i].push_back(a); graph[a].push_back(i); } get_size(1); memset(visited,0,sizeof(visited)); get_m(1); for(int i=1;i<=number;i++){ cout << money[i] << " "; } }

Compilation message (stderr)

birokracija.cpp: In function 'int get_size(int)':
birokracija.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<graph[n].size();i++){
               ~^~~~~~~~~~~~~~~~
birokracija.cpp: In function 'long long int get_m(int)':
birokracija.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<graph[n].size();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...