alexjercan/bugnet huggingface dataset:
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

signed main() {
  int subs[200000];
  int n;
  cin >> n;
  subs[0] = 0;
  for (int i = 1; i < n; i++) {
    subs[i] = 0;
    int no;
    cin >> no;
    subs[no - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << subs[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

signed main() {
  int subs[100000];
  int n;
  cin >> n;
  subs[0] = 0;
  for (int i = 1; i < n; i++) {
    subs[i] = 0;
    int no;
    cin >> no;
    subs[no - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << subs[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

// in-short-use macros

#define all(c) (c).begin(), (c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010

// main function here

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  int a[n], cnt[n + 10] = {0};
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++)
    cnt[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << cnt[i] << "\\n";
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

// in-short-use macros

#define all(c) (c).begin(), (c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010

// main function here

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  int a[n], cnt[n + 10];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[i + 1] = 0;
  }
  for (int i = 0; i < n; i++)
    cnt[a[i]]++;
  for (int i = 1; i < n; i++)
    cout << cnt[i] << "\\n";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int a[200010];
int ans[200010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 2; i <= n; i++)
    ans[a[i]]++;
  for (int i = 1; i <= n; i++)
    printf("%d\\n", ans[i]);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> v[i];
  }
  int cnt;
  for (int i = 1; i <= n; i++) {
    cnt = count(v.begin(), v.end(), i);
    if (cnt > 0)
      cout << cnt << "\\n";
    else
      cout << "0"
           << "\\n";
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
#include <math.h>
#include <stdio.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll = long long;
using ull = unsigned long long;
const ll INF = 1001001001;

// 10億7。　　　100000007

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  cout << fixed << setprecision(10);
  // cin.tie(0); ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> vec(N - 1);
  vector<ll> vecans(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < N; i++) {
    vecans[i] = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    vecans[vec[i] - 1]++;
  }

  for (int i = 0; i < N; i++) {
    cout << vecans[i] << endl;
  }
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <math.h>
#include <stdio.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll = long long;
using ull = unsigned long long;
const ll INF = 1001001001;

// 10億7。　　　100000007

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  cout << fixed << setprecision(10);
  // cin.tie(0); ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> vec(N - 1);
  vector<ll> vecans(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < N; i++) {
    vecans[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    vecans[vec[i] - 1]++;
  }

  for (int i = 0; i < N; i++) {
    cout << vecans[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int a[200001];

int main() {
  int n;
  cin >> n;
  int temp;
  for (int i = 1; i < n; i++) {
    cin >> temp;
    a[temp]++;
  }

  for (int i = 1; i <= n; i++)
    cout << a[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int a[100001];

int main() {
  int n;
  cin >> n;
  int temp;
  for (int i = 1; i < n; i++) {
    cin >> temp;
    a[temp]++;
  }

  for (int i = 1; i <= n; i++)
    cout << a[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }

  vector<int> count(N + 1);
  for (int i = 0; i < N - 1; i++) {
    count.at(vec.at(i))++;
  }

  for (int i = 1; i <= N; i++) {
    cout << count.at(i) << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }

  vector<int> count(N - 1);
  for (int i = 0; i < N - 1; i++) {
    count.at(vec.at(i))++;
  }

  for (int i = 1; i <= N; i++) {
    cout << count.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int b[n];
  for (int k = 0; k < n; k++) {
    b[k] = 0;
  }

  for (int i = 0; i < n - 1; i++) {
    b[a[i] - 1]++;
  }

  for (int l = 0; l < n; l++) {
    cout << b[l] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int b[n];
  for (int k = 0; k < n; k++) {
    b[k] = 0;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i)
        b[i - 1]++;
    }
  }
  for (int l = 0; l < n; l++) {
    cout << b[l] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vint;

int a[200010];
int ans[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    ans[a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    cout << ans[i] << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vint;

int main() {
  int n;
  cin >> n;
  vint a(n);
  vint ans(n, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
    ans[a[i]]++;
  }
  for (int i = 2; i <= 2; i++)
    cout << a[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, tmp;
  cin >> N;
  int shine[200001] = {0};
  for (int i = 1; i < N; i++) {
    cin >> tmp;
    shine[tmp]++;
  }

  for (int i = 1; i <= N; i++) {
    cout << shine[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> shine(N);
  int tmp;
  shine.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> shine.at(i);
  }

  for (int i = 0; i < N; i++) {
    cout << count(shine.begin(), shine.end(), i + 1) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v1(n);
  vector<int> v2(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cin >> v2[i];
    v1[v2[i] - 1]++;
  }
  for (int i = 0; i < n; ++i) {
    cout << v1[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v1(n);
  vector<int> v2(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    cin >> v2[i];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < n - 1; j++) {
      if (i == v2[j])
        v1[i - 1]++;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << v1[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  int a;
  int ans[200001] = {0};
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    ans[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  int a[200000];
  int ans;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    ans = 0;
    for (int j = i + 1; j <= n; j++) {
      if (a[j] == i) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
int main() {
  int N;
  cin >> N;
  vector<int> ans(N);
  vector<int> A(N - 1);
  rep(i, N - 1) {
    cin >> A.at(i);
    ans.at(A.at(i) - 1)++;
  }
  rep(i, N) { cout << ans.at(i) << endl; }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
int main() {
  int N;
  cin >> N;
  vector<int> ans(N);
  vector<int> A(N - 1);
  rep(i, N - 1) { cin >> A.at(i); }
  rep(i, N) {
    int sum = 0;
    for (int j = i; j < N - 1; j++) {
      if (A.at(j) == i + 1) {
        sum++;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  int a[n + 1] = {0};
  for (int i = 1; i < n; i++) {
    cin >> m;
    a[m - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  cin >> n;
  int a[20000] = {0}, b[20000] = {0};
  for (i = 2; i <= n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  cout << b[1] << endl;
  for (i = 2; i <= n; i++) {
    if (b[a[i]] == 1) {
      cout << b[a[i] + 1] << endl;
    } else if (b[a[i]] > 1) {
      if (b[a[i] + 1] == 0) {
        for (j = 0; j < b[a[i]]; j++) {
          cout << "0" << endl;
        }
        i += b[a[i]] - 1;
      } else {
        cout << b[a[i]] << endl;
        for (j = 0; j < b[a[i]] - 1; j++) {
          cout << "0" << endl;
        }
        i += b[a[i]] - 1;
      }
    }
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n - 1) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> b(n);
  rep(i, 0, n - 1) b[a[i]]++;
  rep(i, 0, n) cout << b[i] << endl;
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n - 1) cin >> a[i];
  vector<int> b(n);
  rep(i, 0, n) b[--a[i]]++;
  rep(i, 0, n) cout << b[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n, i, j;
  cin >> n;
  int a[n], ans[n];
  for (i = 0; i < n; i++)
    ans[i] = 0;
  for (j = 1; j < n; j++) {
    cin >> a[j];
    ans[a[j] - 1]++;
  }
  for (int k = 0; k < n; k++)
    cout << ans[k] << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n, i = 0, j = 0;
  cin >> n;
  int a[n], ans[n];
  for (i = 1; i < n; i++)
    cin >> a[i];
  for (j = 0; j < n; j++) {
    ans[j] = 0;
    ans[a[j] - 1]++;
  }
  for (int k = 0; k < n; k++)
    cout << ans[k] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, P = 0;
  cin >> N;
  vector<int> vec(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  vector<int> BT(N);
  for (int i = 0; i < N - 1; i++) {
    BT.at(vec.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << BT.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, P = 0;
  cin >> N;
  vector<int> vec(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (vec.at(j) == i) {
        P++;
      }
    }
    cout << P << endl;
    P = 0;
  }
  cout << 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  map<int, int> mp;
  for (int i = 1; i <= n; i++)
    mp[i] = 0;
  set<int> st;
  for (int i = 0; i < n - 1; i++) {
    if (st.count(a[i])) {
      mp[a[i]]++;
    } else {
      st.insert(a[i]);
      mp[a[i]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << mp[i] << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  map::at


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  map<int, int> mp;
  set<int> st;
  for (int i = 0; i < n - 1; i++) {
    if (st.count(a[i])) {
      mp[a[i]]++;
    } else {
      st.insert(a[i]);
      mp[a[i]] = 1;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << mp.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, l;
  cin >> n;
  long long a[n + 1] = {0};

  for (i = 0; i < n - 1; i++) {
    cin >> l;
    a[l]++;
  }

  for (i = 1; i <= n; i++) {
    cout << a[i] << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, i, j, cnt = 0;
  scanf("%d", &N);
  int a[N];

  for (i = 0; i < N - 1; i++) {
    scanf("%d", &a[i]);
  }

  for (i = 1; i < N; i++) {
    cnt = 0;
    for (j = 0; j < N - 1; j++) {
      if (a[j] == i)
        cnt++;
    }
    printf("%d\\n", cnt);
  }

  printf("0");

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> ans(n);
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    ans[a - 1]++;
  }
  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N - 1) { cin >> a.at(i + 1); }
  a.at(0) = 0;
  sort(a.begin(), a.end());
  vector<int> buka(N);
  rep(k, N) {
    rep(j, N) {
      if (a.at(j) != 0 && a.at(j) == k) {
        buka.at(k - 1)++;
      }
    }
  }
  rep(i, N) cout << buka.at(i) << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
const int MAXN = 2e5 + 2;

int arr[MAXN];
int main() {
  int N;
  cin >> N;

  for (int i = 2; i <= N; i++) {
    int pos;
    cin >> pos;
    arr[pos]++;
  }
  for (int i = 1; i <= N; i++) {
    cout << arr[i] << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int MAXN = 1e5 + 2;

int arr[MAXN];
int main() {
  int N;
  cin >> N;

  for (int i = 2; i <= N; i++) {
    int pos;
    cin >> pos;
    arr[pos]++;
  }
  for (int i = 1; i <= N; i++) {
    cout << arr[i] << "\\n";
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> s(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> s.at(i);
  }
  vector<int> result(N, 0);
  for (int i = 1; i < N; i++) {
    result.at(s.at(i) - 1) += 1;
  }
  for (int i = 0; i < N; i++) {
    cout << result.at(i) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> s(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> s.at(i);
  }
  vector<int> result(N, 0);
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (s.at(j) == i) {
        result.at(i - 1) += 1;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << result.at(i) << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int A[200000];
  int B[200000] = {0};
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; i++) {
    B[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << B[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int A[200100];
  int B[200100] = {0};
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    B[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << B[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, array[200000], a;
  cin >> n;
  for (int i = 1; i <= n; i++)
    array[i] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a;
    array[a] += 1;
  }
  for (int i = 1; i <= n; i++) {
    cout << array[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, array[200000];
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> array[i];
  }
  sort(array, array + n);
  for (int i = 1; i <= n; i++) {
    int count = 0;
    for (int j = 0; j < n && array[j] <= i; j++) {
      if (array[j] == i)
        count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int ara[200000] = {0}, sh[200000];
  int i, j = 1, k, a, b, s = 0;
  cin >> a;
  for (i = 0; i < a - 1; i++) {
    cin >> sh[i];
    ara[sh[i]]++;
    if (sh[i] > s)
      s = sh[i];
  }
  for (i = 1; i <= s; i++) {
    cout << ara[i] << endl;
  }
  b = a - s;
  for (i = 0; i < b; i++) {
    cout << "0" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int ara[200000] = {0}, sh[200000];
  int i, j = 1, k, a, b, s;
  cin >> a;
  for (i = 0; i < a - 1; i++) {
    cin >> sh[i];
  }
  for (i = 0; i < a - 1;) {
    if (sh[i] == j) {
      ara[j - 1] = ara[j - 1] + 1;
      i++;
    } else {
      j++;
      if (j >= a) {
        j = 0;
      }
    }
  }
  for (i = 0; i < a; i++)
    cout << ara[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> buka(n - 1, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> a.at(i);
    buka.at(a.at(i) - 1)++;
  }

  for (int i = 0; i < n - 1; i++) {
    cout << buka.at(i) << endl;
  }
  cout << "0" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> buka(n - 1, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (a.at(j) == i + 1) {
        buka.at(i)++;
      }
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << buka.at(i) << endl;
  }
  cout << "0" << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int i, n;
  int a[200010] = {0};
  int buka[200010] = {0};

  cin >> n;

  for (i = 2; i <= n; i++)
    cin >> a[i];

  for (i = 2; i <= n; i++)
    buka[a[i]]++;

  for (i = 1; i <= n; i++)
    cout << buka[i] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int i, j, n;
  int buka[2 * 100000] = {0};
  int a1[2 * 100000] = {0};

  cin >> n;

  for (i = 2; i <= n; i++) {
    cin >> a1[i];
  }

  i = 1;
  while (i != n + 1) {
    for (j = 2; j <= n; j++) {
      if (i == a1[j])
        buka[i]++;
    }
    i++;
  }

  for (i = 1; i <= n; i++) {
    cout << buka[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N - 1);
  vector<int> vv(N);
  for (int X = 0; X < N - 1; X++) {
    cin >> vec.at(X);
    vv.at(vec.at(X) - 1) += 1;
  }
  for (int X = 0; X < N; X++) {
    cout << vv.at(X) << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 6)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  vector<int> vv(N + 1);
  for (int X = 0; X < N; X++) {
    cin >> vec.at(X);
    vv.at(vec.at(X) - 1) += 1;
  }
  for (int X = 0; X < N + 1; X++) {
    cout << vv.at(X) << endl;
  }
}