Submission #580134

# Submission time Handle Problem Language Result Execution time Memory
580134 2022-06-20T16:02:26 Z emad234 Birokracija (COCI18_birokracija) C++17
60 / 100
1000 ms 10700 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1364 KB Output is correct
2 Correct 530 ms 1668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 3924 KB Output is correct
2 Execution timed out 1092 ms 4012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 111 ms 10700 KB Output is correct
2 Execution timed out 1085 ms 9780 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 137 ms 10656 KB Output is correct
2 Execution timed out 1082 ms 9792 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 10520 KB Output is correct
2 Execution timed out 1081 ms 9756 KB Time limit exceeded
3 Halted 0 ms 0 KB -