alexjercan/bugnet huggingface dataset:
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int N;
  cin >> N;
  vector<int> boss(N - 1);
  vector<int> ans(N);

  for (int i = 0; i < N - 1; i++) {
    cin >> boss.at(i);
    ans.at(boss.at(i) - 1)++;
  }

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

Error: TLE

Fixed submission:

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

int main() {

  int N;
  cin >> N;

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

  vector<int> n(N);
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      if (m.at(i) == j + 1) {
        n.at(j)++;
      }
    }
  }

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

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> ans(n, 0);
  while (--n) {
    int a;
    cin >> a;
    ++ans[a - 1];
  }
  for (auto e : ans)
    cout << e << endl;
}


Error: -11

Fixed submission:

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

#include <iostream>
using namespace std;
int main() {
  unsigned long int n, num[200000] = {0}, i, value;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> value;
    num[value - 1]++;
  }
  for (i = 0; i < n; i++) {
    cout << num[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  unsigned long int n, num[200000], i, j, count;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> num[i];
  }
  for (i = 0; i < n; i++) {
    count = 0;
    for (j = 0; j < n; j++) {
      if (num[j] == i + 1)
        count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  N--;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  vector<int> ans(N + 1);
  for (int i = 0; i < N; i++) {
    ans.at(A.at(i) - 1)++;
  }
  for (auto a : ans)
    cout << a << "\\n";
}

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 5)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans.at(A.at(i) - 1)++;
  }
  for (auto a : ans)
    cout << a << "\\n";
}
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);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int count = 0;
  int c = 0;
  for (int i = 1; i < N + 1; i++) {
    count = 0;
    for (int j = c; j < N - 1; j++) {
      if (A.at(j) == i) {
        count++;
      } else {
        c = j;
        break;
      }
    }
    cout << count << endl;
  }
}


Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int N;
// int A[220000];
vector<int> res;
int main() {
  cin >> N;
  res.resize(N, 0);
  rep(i, N - 1) {
    int t;
    cin >> t;
    res[t - 1] += 1;
  }
  rep(i, N) { cout << res[i] << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int N;
// int A[220000];
int res[22000];
int main() {
  cin >> N;
  memset(res, 0, sizeof(res));
  rep(i, N - 1) {
    int t;
    cin >> t;
    res[t - 1] += 1;
  }
  rep(i, N) { cout << res[i] << endl; }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {

  int A[200001] = {0};
  int N;
  int chk;
  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    cin >> chk;
    A[chk]++;
  }
  for (int i = 1; i <= N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {

  int A[20001] = {0};
  int N;
  int chk;
  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    cin >> chk;
    A[chk]++;
  }
  for (int i = 1; i <= N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;

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

#include <iostream>
using namespace std;

int main(void) {
  int N;
  int A[200001];
  cin >> N;
  for (int i = 2; i <= N; i++) {
    cin >> A[i];
  }

  int ans[200001];
  for (int j = 2; j <= N; j++) {
    ans[A[j]]++;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int N;
  int A[200001];
  cin >> N;
  for (int i = 2; i <= N; i++) {
    cin >> A[i];
  }

  int ans[200001];
  for (int i = 1; i <= N; i++) {
    for (int j = 2; j <= N; j++) {
      if (A[j] == i) {
        ans[i]++;
      }
    }
  }

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

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main() {
  lli N;
  cin >> N;
  lli A[N];
  for (lli i = 0; i < N; i++)
    A[i] = 0;
  for (lli i = 1; i < N; i++) {
    lli x;
    cin >> x;
    A[x - 1]++;
  }
  for (lli i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main() {
  lli N, A[N];
  cin >> N;
  for (lli i = 0; i < N; i++)
    A[i] = 0;
  for (lli i = 1; i < N; i++) {
    lli x;
    cin >> x;
    A[x - 1]++;
  }
  for (lli i = 0; i < N; i++) {
    cout << A[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> vec1(N - 1);
  vector<int> vec2(N);

  for (int i = 0; i < N - 1; i++) {
    cin >> vec1.at(i);
    vec2.at(vec1.at(i) - 1)++;
  }

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

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;

  vector<int> vec1(N - 1);
  vector<int> vec2(N);

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      if (vec1.at(i) == j) {
        vec2.at(j - 1)++;
      }
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  sort(ALL(a));
  vector<int> ans(n + 1);
  ans[0] = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = sum; j <= n; j++) {
      if (a[j + 1] != i) {
        ans[i] = j - sum;
        sum = j;
        break;
      }
    }
  }
  rep(i, n) { cout << ans[i + 1] << endl; }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  sort(ALL(a));
  vector<int> ans(n + 1);
  ans[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    ans[i] = count(a.begin() + ans[i - 1], a.end(), i);
  }
  rep(i, n) { cout << ans[i + 1] << endl; }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long N, M, value;
  cin >> N;
  vector<int> count(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> value;
    count[value - 1]++;
  }
  for (int i = 0; i < N; i++)
    cout << count[i] << ' ';
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long N, M, value;
  cin >> N;
  vector<int> count;
  for (int i = 0; i < N - 1; i++) {
    cin >> value;
    count[value - 1]++;
  }
  for (int i = 0; i < N; i++)
    cout << count[i] << ' ';
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  int A;
  vector<int> sya(N);

  for (int i = 0; i < N - 1; ++i) {
    cin >> A;
    sya.at(A - 1) += 1;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> num(N - 1);
  vector<int> sya(N);

  for (int i = 0; i < N - 1; ++i) {
    cin >> num.at(i);
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < N - 1; ++j) {
      if (num.at(j) == i) {
        sya.at(i - 1) += 1;
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    cout << sya.at(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;

  long long A[N], subord[N];

  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
    subord[i] = 0;
  }

  for (int j = 0; j < N - 1; j++) {
    subord[A[j] - 1]++;
  }
  for (int n = 0; n < N - 1; n++) {
    cout << subord[n] << endl;
  }
  cout << 0 << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  int N;
  cin >> N;

  long long A[N], subord[N];

  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
    subord[i] = 0;
  }

  for (int j = 0; j < N - 1; j++) {
    for (int m = 0; m < N; m++) {
      if (j == A[m] - 1) {
        subord[j]++;
      }
    }
  }
  for (int n = 0; n < N - 1; n++) {
    cout << subord[n] << endl;
  }
  cout << 0 << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

#include <iostream>
#include <vector>

using namespace std;

int main() {

  int N, i;
  cin >> N;
  vector<int> ans(N + 1);

  for (i = 2; i <= N; i++) {
    int a;
    cin >> a;
    ans[a]++;
  }

  for (i = 1; i <= N; i++)
    cout << ans[i] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  long N;
  int i, j, count, start = 1;
  cin >> N;
  vector<int> a(N);

  for (i = 1; i < N; i++)
    cin >> a[i];

  for (i = 1; i <= N; i++) {
    count = 0;
    for (j = start; j < N; j++) {
      if (a[j] == i) {
        count += 1;
        start += 1;
      }
    }
    cout << count << 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> vec(n);
  for (int i = 0; i < n - 1; i++) {
    int j;
    cin >> j;
    vec.at(j - 1) += 1;
  }
  for (int i = 0; i < n - 1; i++) {
    cout << vec.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> vec(n);
  for (int i; i < n; i++) {
    cin >> vec.at(i);
  }
  for (int i; i < n; i++) {
    cout << count(vec.begin(), vec.end(), i + 1) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  // Get total number of subordinates provided
  int n;
  cin >> n;

  // Store all subordinates in an array
  int subordinates[n - 1];
  for (int i = 0; i < n - 1; i++) {
    cin >> subordinates[i];
  }

  // Calculate no. of subordinate for each numbered boss
  int bosses[n + 1]; // we are not using index 0, hence n+1 instesad of n
  memset(bosses, 0, sizeof(bosses)); // placing 0 at each position
  for (int i = 0; i < n - 1; i++) {  // iterating subordinates, hence n-1
    bosses[subordinates[i]]++;
  }

  // print subordinates at each boss-position from 1 to n
  for (int i = 1; i < n + 1; i++) {
    cout << bosses[i] << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <vector>
using std::vector;

int main() {
  int num_of_members{};
  vector<int> members(200000);

  scanf("%d", &num_of_members);

  while (num_of_members - 1 > 0) {
    int num{};
    scanf("%d", &num);
    members.at(num) += 1;
  }

  for (int i = 1; i <= num_of_members; i++) {
    printf("%d\\n", members.at(i));
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mod 1e9 + 7
typedef long long ll;

int main() {
  int n;
  std::cin >> n;
  int a[n + 5];
  for (int i = 2; i <= n; i++)
    std::cin >> a[i];
  int sum[n] = {0};
  for (int i = 2; i <= n; i++) {
    sum[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++)
    std::cout << sum[i] << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1e9 + 7
typedef long long ll;

int main() {
  int n;
  std::cin >> n;
  int a[n + 5];
  for (int i = 2; i <= n; i++)
    std::cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int count = 0;
    for (int j = 2; j <= n; j++) {
      if (a[j] == i)
        count++;
    }
    std::cout << count << '\\n';
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  lint n;
  cin >> n;
  vector<lint> vc;
  rep(i, n - 1) {
    int x;
    cin >> x;
    vc.push_back(x);
  }
  vector<lint> cnt(n);
  rep(i, n - 1) cnt[(vc[i] - 1)]++;
  rep(i, n) cout << cnt[i] << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  lint n;
  cin >> n;
  vector<lint> vc;
  rep(i, n - 1) {
    int x;
    cin >> x;
    vc.push_back(x);
  }
  vector<lint> cnt(5);
  rep(i, n - 1) cnt[(vc[i] - 1)]++;
  rep(i, n) cout << cnt[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ms memset
// #define MAXN 10005
// #define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii>> dij;

int N, n;
int A[200010];

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

  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    cin >> n;
    A[n]++;
  }

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

  return 0;
}

Error: 0

Fixed submission:

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ms memset
// #define MAXN 10005
// #define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii>> dij;

int N, n;
int A[100010];

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

  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    cin >> n;
    A[n]++;
  }

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

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

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> data(n);
  rep(i, n) {
    data.at(i) = make_pair(i, 0);
    if (i == 0) {
      continue;
    } else {
      int josi;
      cin >> josi;
      data.at(josi - 1).second++;
    }
  }

  rep(i, n) { cout << data.at(i).second << endl; }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  /*
  vector<int> josi(n - 1);
  rep(i,n-1){
      cin >> josi.at(i);
  }
  */
  vector<pair<int, int>> data(n);
  rep(i, n) {
    if (i == 0) {
      data.at(i) = make_pair(i, 0);
    } else {
      int josi;
      cin >> josi;
      data.at(i) = make_pair(i, josi - 1);
    }
  }

  vector<int> ans(n);
  rep(i, n) {
    ans.at(i) = 0;
    int search = data.at(i).first;
    for (int j = i + 1; j < n; j++) {
      int num, target;
      tie(num, target) = data.at(j);
      if (target == i) {
        ans.at(i)++;
      }
    }
  }

  rep(i, n) { cout << ans.at(i) << endl; }

  return 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 < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> b(200200);
  int ans = 0;
  rep(i, n - 1) {
    cin >> a.at(i);
    b.at(a.at(i))++;
  }
  rep2(i, 1, n + 1) { cout << b.at(i) << endl; }
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  vector<int> b(200000);
  int ans = 0;
  rep(i, n - 1) {
    cin >> a.at(i);
    b.at(a.at(i))++;
  }
  rep2(i, 1, n + 1) { cout << b.at(i) << 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> A(N - 1);
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++)
    cin >> A[i];

  for (int j = 0; j < N - 1; j++) {
    B[A[j] - 1]++;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;

  vector<int> A(N - 1);
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++)
    cin >> A[i];

  for (int j = 0; j < N - 1; j++) {
    for (int k = 0; k < N - 1; k++) {
      if (A[j] == k + 1) {
        B[k]++;
        break;
      }
    }
  }

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

  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon {
  initon() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  };
};
signed main() {
  int n;
  cin >> n;
  vector<int> a(200010);
  vector<int> ans(200010);
  REP(i, 200010) {
    a[i] = 0;
    ans[i] = 0;
  }
  for (int i = 2; i <= n; i++)
    cin >> a[i];
  for (int i = 2; i <= n; i++)
    ans[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << ans[i] << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon {
  initon() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  };
};
signed main() {
  int n;
  cin >> n;
  vector<int> a(20010);
  vector<int> ans(200010);
  REP(i, 200010) {
    a[i] = 0;
    ans[i] = 0;
  }
  for (int i = 2; i <= n; i++)
    cin >> a[i];
  for (int i = 2; i <= n; i++)
    ans[a[i]]++;
  for (int i = 1; i <= n; i++)
    cout << ans[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
#include <math.h>

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>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  int A[1000000];
  int count;

  cin >> N;
  for (int i = 0; i < N - 1; ++i)
    cin >> A[i];

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

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

int main() {
  int em;
  cin >> em;

  vector<int> data(em);
  vector<int> num(em + 1);

  for (int i = 2; i <= em; i++) {
    cin >> data.at(i - 1);
  }

  for (int i = 2; i <= em; i++) {
    num.at(data.at(i - 1))++;
  }

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

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


Fixed submission:

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

int main() {
  int em;
  cin >> em;

  vector<int> data(em);
  vector<int> num(em);

  for (int i = 2; i <= em; i++) {
    cin >> data.at(i);
  }

  for (int i = 2; i <= em; i++) {
    num.at(data.at(i))++;
  }

  for (int i = 1; i <= em; i++) {
    cout << num.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(type, i, a, b) for (type i = a; i < b; i++)
using namespace std;

int main() {
  int n;
  int x, ans[200002];
  scanf("%d", &n);
  REP(int, i, 1, n + 1) { ans[i] = 0; }
  REP(int, i, 2, n + 1) {
    scanf("%d", &x);
    ans[x]++;
  }

  REP(int, i, 1, n + 1) { printf("%d\\n", ans[i]); }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(type, i, a, b) for (type i = a; i < b; i++)
using namespace std;

int main() {
  int n;
  int x, ans[20002];
  cin >> n;
  REP(int, i, 1, n + 1) { ans[i] = 0; }
  REP(int, i, 2, n + 1) {
    cin >> x;
    ans[x]++;
  }

  REP(int, i, 1, n + 1) { cout << ans[i] << endl; }
}