Submission #580134

#TimeUsernameProblemLanguageResultExecution timeMemory
580134emad234Birokracija (COCI18_birokracija)C++17
60 / 100
1092 ms10700 KiB
#include <bits/stdc++.h> #define all(v) ((v).begin(),(v).end()) #define int long long using namespace std; const int mod = 1e9 + 7; const int mxN = 2e6 + 1; vector<vector<int>>v; vector<int>add; int ans[mxN]; signed main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin >>n; v.resize(n +1 ); for(int i = 2; i <= n;i++){ int x;cin>>x; v[x].push_back(i); } while(v[1].size()){ add.clear(); int i = 1; int j = 1; int vali = 1; int val = 1; int cnt = 0; int valj; while(!v[vali].empty()){ cnt++; valj = vali; i = min_element(v[vali].begin(),v[vali].end()) - v[vali].begin(); val++; vali = v[vali][i]; add.push_back(vali); } ans[1] += val; for(int k = 0;k < add.size();k++){ ans[add[k]] += val - (k + 1); } v[valj].erase(v[valj].begin() + i); } ans[1]++; for(int i = 1;i <= n;i++){ cout <<ans[i]<<' '; } }

Compilation message (stderr)

birokracija.cpp: In function 'int main()':
birokracija.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |       for(int k = 0;k < add.size();k++){
      |                     ~~^~~~~~~~~~~~
birokracija.cpp:23:11: warning: unused variable 'j' [-Wunused-variable]
   23 |       int j = 1;
      |           ^
birokracija.cpp:40:13: warning: 'valj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |       v[valj].erase(v[valj].begin() + 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...