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

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int v[200000];
  int n;
  int tmp;
  cin >> n;
  for (int i = 0; i < 200000; i++) {
    v[i] = 0;
  }
  for (int i = 2; i <= n; i++) {
    cin >> tmp;
    v[tmp - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << v[i] << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int v[100000];
  int n;
  int tmp;
  cin >> n;
  for (int i = 0; i < 100000; i++) {
    v[i] = 0;
  }
  for (int i = 2; i <= n; i++) {
    cin >> tmp;
    v[tmp - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << v[i] << endl;
  }
}
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> 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 l = 0; l < N; l++) {
    cout << b[l] << 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> b(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> a[i];
  }

  for (int j = 0; j < N - 1; j++) {
    for (int k = 1; k < N; k++) {
      if (a[j] == k)
        b[k - 1]++;
    }
  }

  for (int l = 0; l < N; l++) {
    cout << b[l] << endl;
  }
}
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++)
// 桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> ans(n);
  rep(i, n) {
    cin >> v[i + 1];
    v[i + 1]--;
  }
  rep(j, n) { ans[v[j]]++; }
  ans[0]--;
  rep(k, n) { cout << ans[k] << endl; }
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう

#define rep(i, n) for (int i = 0; i < n; i++)
long long SUM(vector<int> Vec) { // 配列の和
  int n = Vec.size();
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += Vec[i];
  }
  return sum;
}
// 桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> ans(n);
  rep(i, n) {
    cin >> v[i];
    v[i]--;
  }
  rep(j, n) { ans[v[j]]++; }
  rep(k, n) { cout << ans[k] << endl; }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  map<int, int> mp;
  cin >> n;
  vector<int> a(n);
  rep(i, n - 1) {
    cin >> a[i];
    mp[a[i]]++;
  }
  // for(auto p:mp){
  // 	cout<<p.second<<endl;
  // }
  for (int i = 1; i <= n; ++i) {
    cout << mp[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<long long> so;
int main() {
  long long n, p;
  cin >> n;
  p = n - 1;
  while (p--) {
    long long p;
    cin >> p;
    so.push_back(p);
  }
  int s = 1;
  while (s <= n) {
    int count = 0;
    for (int i = 0; i < so.size(); i++) {
      if (s == so[i])
        count++;
    }
    cout << count << endl;
    s++;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define AC                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define endl '\\n'
int main() {
  AC int a[200000], b[200000], n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
    a[b[i] - 1]++;
  }
  for (int i = 0; i < n; i++)
    cout << a[i] << '\\n';
}

Error: 0

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 2; i <= n; i++)
    cin >> a[i];
  int v[n + 1];
  for (int i = 1; i <= n; i++) {
    v[i] = 0;
  }
  for (int i = 2; i <= n; i++) {
    v[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << v[i] << "\\n";
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 2; i <= n; i++)
    cin >> a[i];
  int v[n + 1];
  for (int i = 1; i <= n; i++) {
    v[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    v[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << v[i] << "\\n";
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int N = 200005;

vector<int> g[N];

int sz[N];
int dfs(int u, int p) {
  sz[u] = 1;
  for (int v : g[u])
    if (v != p)
      sz[u] += dfs(v, u);
  return sz[u];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    sz[p]++;
    g[p].push_back(i);
  }
  // 	dfs(1, 1);

  for (int i = 1; i <= n; i++) {
    printf("%d\\n", sz[i]);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

vector<int> g[N];

int sz[N];
int dfs(int u, int p) {
  sz[u] = 1;
  for (int v : g[u])
    if (v != p)
      sz[u] += dfs(v, u);
  return sz[u];
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    sz[p]++;
    g[p].push_back(i);
  }
  // 	dfs(1, 1);

  for (int i = 1; i <= n; i++) {
    printf("%d\\n", sz[i]);
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N = 0;

  cin >> N;
  vector<int> A(N);
  vector<int> B(N);

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

  for (int i = 1; i < N; i++) {
    int j = A.at(i) - 1;
    B.at(j)++;
  }

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


Error: TLE

Fixed submission:

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

int main() {
  int N = 0;

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

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

  for (int i = 0; i < N; i++) {
    cout << B.at(i) << endl;
  }
}
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 - 1);
  vector<int> count(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
    count.at(vec.at(i) - 1)++;
  }
  for (int j = 0; j < N; j++) {
    cout << count.at(j) << endl;
  }
}

Error: TLE

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);
  }
  for (int j = 0; j < N; j++) {
    int ans = count(vec.begin(), vec.end(), j + 1);
    cout << ans << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\\n"
#define MAXN 2 * 100123
#define ll long long
#define INF INT_MAX
#define FORE(i, m, n) for (int i = m; i < n; i++)
#define FOR(i, n) FORE(i, 0, n)
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define ps(v) push_back(v)
#define ms(v, x) memset(v, x, sizeof(v))

using namespace std;

int n, v;
int freq[MAXN];

int main() {
  _ cin >> n;

  FOR(i, n - 1) {
    cin >> v;
    freq[v]++;
  }

  FORE(i, 1, n + 1) { cout << freq[i] << endl; }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\\n"
#define MAXN 100123
#define ll long long
#define INF INT_MAX
#define FORE(i, m, n) for (int i = m; i < n; i++)
#define FOR(i, n) FORE(i, 0, n)
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define ps(v) push_back(v)
#define ms(v, x) memset(v, x, sizeof(v))

using namespace std;

int n, v;
int freq[MAXN];

int main() {
  _ cin >> n;

  FOR(i, n - 1) {
    cin >> v;
    freq[v]++;
  }

  FORE(i, 1, n + 1) { cout << freq[i] << endl; }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll b[300000 + 20];
int main() {

  ll n, i, x;

  cin >> n;

  for (i = 2; i <= n; i++) {
    cin >> x;
    b[x]++;
  }
  for (i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {

  ll n, i, x;
  // vector<ll>a;
  ll b[100000 + 20];

  cin >> n;

  for (i = 2; i <= n; i++) {
    cin >> x;
    // a.push_back(x);
    // b.push_back(a[i]);
    b[x]++;
  }
  for (i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> arr;
  arr.assign(n, 0);
  int input;
  int prev;
  cin >> prev;
  arr[prev - 1]++;
  for (int i = 0; i < n - 2; i++) {
    cin >> input;
    if (prev == input)
      arr[prev - 1]++;
    else {
      prev = input;
      arr[prev - 1]++;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << arr[i] << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> arr;
  int input;
  for (int i = 0; i < n - 1; i++) {
    cin >> input;
    arr.push_back(input);
  }
  for (int i = 0; i < n; i++) {
    cout << count(arr.begin() + i, arr.end(), i + 1) << "\\n";
  }

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n - 1];
  long long int arr[100000] = {0};
  for (long long int i = 0; i < n - 1; i++) {
    cin >> a[i];
    arr[a[i]]++;
  }
  for (long long int i = 1; i <= n; i++) {
    cout << arr[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int a[11451419];
int b[11451419] = {};

int main() {
  int n;

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

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

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

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n;
  int a[1145141919];
  int b[1145141919] = {};

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

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

  for (int i = 0; i < n; i++) {
    if (b[i] != 0) {
      cout << b[i] << endl;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int N = 100005;
#define ll long long
int cmp(int a, int b) { return a > b; }
int gcd(int x, int y) {
  while (y ^= x ^= y ^= x %= y)
    ;
  return x;
}
int main() {
  int n;
  cin >> n;
  int a[200005], f[200005];
  memset(f, 0, sizeof(f));
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << f[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int N = 100005;
#define ll long long
int cmp(int a, int b) { return a > b; }
int gcd(int x, int y) {
  while (y ^= x ^= y ^= x %= y)
    ;
  return x;
}
int main() {
  int n;
  cin >> n;
  int a[100005], f[100005];
  memset(f, 0, sizeof(f));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 1)
      f[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << f[a[i]] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a.at(i);
  }
  vector<int> sum(n);
  for (int i = 0; i < n - 1; i++) {
    sum.at(a.at(i) - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << sum.at(i) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

int gcd(int n1, int n2) {
  if (n1 % n2 == 0)
    return n2;
  else
    return gcd(n2, n1 % n2);
}

int main() {
  int n;
  cin >> n;
  std::vector<int> v(n, 0);
  for (int i = 0; i <= n - 2; i++) {
    int a;
    cin >> a, a--;
    v[a]++;
  }
  rep(i, n) cout << v[i] << endl;
}


Error: TLE

Fixed submission:

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

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

#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);
  }
  vector<int> b(N, 0);
  for (int i = 0; i < N - 1; i++) {
    int ji = a.at(i) - 1;
    b.at(ji) = b.at(ji) + 1;
  }
  for (int i = 0; i < N; i++) {
    cout << b.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 N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> a.at(i);
  }
  vector<int> b(N, 0);
  for (int i = 0; i < N - 1; i++) {
    int ji = a.at(i) - 1;
    b.at(ji) = b.at(ji) + 1;
  }
  for (int i = 0; i < 100; i++) {
    cout << b.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct node {
  int num;
  int sco;
} b[200005];

int main() {
  int n, i, j;
  cin >> n;
  int a[n];

  for (i = 1; i <= n; i++)
    b[i].num = i;
  for (i = 1; i < n; i++)
    cin >> a[i];

  for (i = 1; i < n; i++)
    b[a[i]].sco++;

  for (i = 1; i <= n; i++)
    cout << b[i].sco << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

struct node {
  int num;
  int sco;
} b[200005];

int main() {
  int n, i, j;
  cin >> n;
  int a[n];

  for (i = 1; i <= n; i++)
    b[i].num = i;
  for (i = 1; i < n; i++)
    cin >> a[i];

  for (i = 1; i < n; i++)
    for (j = 1; j <= n; j++) {
      if (a[i] == b[j].num)
        b[j].sco++;
    }

  for (i = 1; i <= n; i++)
    cout << b[i].sco << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, temp;
  cin >> n;
  vector<int> v2(n + 1, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> temp;
    v2[temp]++;
  }
  for (int i = 1; i < n + 1; i++) {
    cout << v2[i] << "\\n";
  }
}

Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, temp;
  cin >> n;
  vector<int> v;
  vector<int> v2(n, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> temp;
    v.push_back(temp);
  }
  int count = 0;
  for (int i = 1; i < n; i++) {
    count = 0;
    for (int j = 0; j < n - 1; j++) {
      if (v[j] == i) {
        count++;
      }
    }
    v2[i - 1] = count;
  }
  for (int i = 0; i < n; i++) {
    cout << v2[i] << "\\n";
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define NMAX 1000000
int main() {
  int N, A;
  cin >> N;
  int v[N + 1];
  std::fill_n(v, N + 1, 0);
  for (int i = 2; i <= N; i++) {
    cin >> A;
    v[A - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << v[i] << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define NMAX 1000000
int main() {
  int N, S = 0;
  int A;
  cin >> N;
  int *v;
  v = new int(N + 1);
  std::fill_n(v, N + 1, 0);
  for (int i = 2; i <= N; i++) {
    cin >> A;
    v[A - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << v[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> vec(N);
  int k;
  for (int i = 0; i < N - 1; i++) {
    cin >> k;
    vec[k - 1]++;
  }
  for (int x : vec) {
    cout << x << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  vector<int> vec;
  cin >> N;
  int k;

  for (int i = 0; i < N - 1; i++) {
    cin >> k;
    vec.push_back(k);
  }
  for (int i = 0; i < N; i++) {
    int count = 0;
    for (int j = 0; j < N - 1; j++) {
      if (i + 1 == vec[j]) {
        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 n = 0;
  cin >> n;
  int a[n], d[n], t[n];
  a[0] = 1;
  t[0] = 1;
  d[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    t[i] = i + 1;
    d[i] = 0;
  }
  // for(int i=0; i<n; i++){
  for (int j = 1; j < n; j++) {
    //     if(t[i] == a[j]){
    //  d[i] = d[i] + 1;
    //  }
    d[a[j] - 1] = d[a[j] - 1] + 1;
  }
  // }

  for (int q = 0; q < n; q++) {
    cout << d[q] << endl;
  }
}


Error: TLE

Fixed submission:

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

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

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n[100001];
int main() {
  int a, b;
  cin >> a;
  for (int i = 1; i < a; i++) {
    cin >> b;
    n[b] += 1;
  }
  for (int i = 1; i <= a; i++) {
    cout << n[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> A(N - 1);
  vector<int> B(N);

  for (int x : A) {
    cin >> x;
    B.at(x - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << B.at(i) << 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 5)


Fixed submission:

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

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

  for (int x : A) {
    cin >> x;
    B.at(x - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << B.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // GCC5.4.1で配列の範囲外アクセスをエラーにする

// cmdで g++ test.cpp とするとコンパイルできる
// 制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(), x.end()
typedef long long ll;            // long long
typedef pair<int, int> pii;      // pair<int,int>
typedef vector<int> vi;          // vector<int>
typedef vector<vector<int>> vvi; // vector<vector<int>>
typedef vector<ll> vll;          // vector<long long>
typedef vector<vector<ll>> vvll; // vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int>> gpq; // 逆順priority_queue
typedef priority_queue<int> pq;

// const int MOD=998244353;
const int MOD = 1000000007; // 10^9+7
const double PI = 3.1415926535;

ll gcd(ll x, ll y) {
  ll b = max(x, y), s = min(x, y);
  if (s <= 0)
    return b;
  return gcd(s, b % s);
}

int main() {
  int N, a;
  cin >> N;
  vi buka(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> a;
    a--;
    buka.at(a) = buka.at(a) + 1;
  }
  for (int i = 0; i < N; i++) {
    cout << buka[i] << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // GCC5.4.1で配列の範囲外アクセスをエラーにする

// cmdで g++ test.cpp とするとコンパイルできる
// 制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(), x.end()
typedef long long ll;            // long long
typedef pair<int, int> pii;      // pair<int,int>
typedef vector<int> vi;          // vector<int>
typedef vector<vector<int>> vvi; // vector<vector<int>>
typedef vector<ll> vll;          // vector<long long>
typedef vector<vector<ll>> vvll; // vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int>> gpq; // 逆順priority_queue
typedef priority_queue<int> pq;

// const int MOD=998244353;
const int MOD = 1000000007; // 10^9+7
const double PI = 3.1415926535;

ll gcd(ll x, ll y) {
  ll b = max(x, y), s = min(x, y);
  if (s <= 0)
    return b;
  return gcd(s, b % s);
}

int main() {
  int N;
  vi buka(N, 0);
  cin >> N;
  int a;
  for (int i = 1; i < N; i++) {
    cin >> a;
    buka[a - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << buka[i] << endl;
  }
}