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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define reps(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';

using namespace std;

int main(void) {
  ll N;
  cin >> N;
  ll A;
  // MEMSET(co, 0);
  ll chi[500005];
  MEMSET(chi, 0);
  rep1(i, N - 1) {
    cin >> A;
    chi[A - 1]++;
  }
  rep(i, N) { cout << chi[i] << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define reps(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';

using namespace std;

int main(void) {
  ll N;
  cin >> N;
  ll A;
  // MEMSET(co, 0);
  vector<ll> chi[100005];
  rep1(i, N - 1) {
    cin >> A;
    chi[A - 1].push_back(i);
  }
  rep(i, N) { cout << chi[i].size() << endl; }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> ans(n);

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

Error: WA

Fixed submission:

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

int main() {
  int n, a;
  cin >> n >> a;
  int input[] = {};
  int ans = 0;

  for (int i = 0; i < a; i++) {
    cin >> input[i - 1];
    ans += input[i - 1];
  };

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

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int main() {
  int n, a;
  cin >> n;
  vector<int> vec(n, 0);

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

  for (int i = 0; i < n; i++)
    cout << vec[i] << ' ';
  cout << endl;
}


Error: WA

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int main() {
  int n, a;
  cin >> n;
  vector<int> vec(n, 0);

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

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

#include <bits/stdc++.h>

#define rep(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define ll long long
#define out(n) cout << #n << ' = ' << '\\n'

using namespace std;

const int maxn = 2e5 + 10;
int a[maxn];
int ans[maxn];

int main() {
  int n;
  cin >> n;
  rep(i, 0, n - 1) {
    cin >> a[i];
    ans[a[i]]++;
  }
  rep(i, 1, n + 1) cout << ans[i] << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define ll long long
#define out(n) cout << #n << ' = ' << '\\n'

using namespace std;

const int maxn = 1e5;
int a[maxn];
int ans[maxn];

int main() {
  int n;
  cin >> n;
  rep(i, 0, n - 1) {
    cin >> a[i];
    ans[a[i]]++;
  }
  rep(i, 1, n + 1) cout << ans[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> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n - 1; i++) {

    ans[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << 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[i];
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n - 1; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == a[i])
        ans[j - 1]++;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}
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 ll = long long;
using P = pair<int, int>;

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

  vector<int> A(N - 1);
  vector<int> cunt(N, 0);
  rep(i, N - 1) cin >> A[i];

  rep(i, N - 1) { cunt[A[i] - 1]++; }

  rep(i, N) cout << cunt[i] << endl;
  return 0;
}

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>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  vector<int> A(N - 1);
  vector<int> cunt(N, 0);

  cin >> N;
  rep(i, N - 1) cin >> A[i];

  rep(i, N - 1) { cunt[A[i] - 1]++; }

  rep(i, N) cout << cunt[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> vec(N - 1);
  vector<int> vecn(N, 0);
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  for (int j = 0; j < N - 1; j++) {
    vecn.at(vec.at(j) - 1) += 1;
  }
  for (int j = 0; j < N; j++) {
    cout << vecn.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);
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  for (int j = 1; j <= N - 1; j++) {
    count = 0;
    for (int k = j - 1; k < N - 1; k++) {
      if (vec.at(k) == j)
        count++;
    }
    cout << count << endl;
  }
  cout << 0 << 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> vec2(N);
  for (int i = 0; i < N - 1; i++) {
    int a;
    cin >> a;
    vec.at(i) = a;
  }
  for (int i = 0; i < N - 1; i++) {
    vec2.at(vec.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << vec2.at(i) << endl;
  }
}


Error: WA

Fixed submission:

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

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = 1; i <= x; i++)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;

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


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = 1; i <= x; i++)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

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

#include <iostream>
using namespace std;
int main() {
  int cantidades[1000000] = {0};
  int a, b;
  cin >> a;
  for (int i = 0; i < a - 1; i++) {
    cin >> b;
    cantidades[(b - 1)]++;
  }
  for (int i = 0; i < a; i++) {
    cout << cantidades[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int cantidades[100000] = {0};
  int a, b;
  cin >> a;
  for (int i = 0; i < a - 1; i++) {
    cin >> b;
    cantidades[b - 1]++;
  }
  for (int i = 0; i < a; i++) {
    cout << cantidades[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, M;
string S;
long double R;

int main() {

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

  for (int i = 0; i < N - 1; i++) {

    cin >> A[i];
    num[i] = 0;
  }

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


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, M;
string S;
long double R;

int main() {

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

  for (int i = 0; i < N; i++) {
    if (i == 0) {
      A[i] = 0;
    }
    cin >> A[i];
    num[i] = 0;
  }

  for (int i = 1; i < N; i++) {
    num[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << num[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> A(N);
  A.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> result(N);
  for (int i = 1; i < N; i++) {
    result.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << result.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);
  A.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> result(N);
  for (int i = 0; i < N; i++) {
    result.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << result.at(i);
  }
  cout << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
  int n;
  cin >> n;
  vec b(n);
  vec a(n);
  rip(i, n - 1) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  rip(i, n) cout << b[i] << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
  int n;
  cin >> n;
  vec b(n);
  vec a(n);
  rip(i, n) {
    cin >> a[i + 1];
    b[a[i + 1]]++;
  }
  rip(i, n - 1) cout << b[i + 1] << 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);
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    B.at(A.at(i) - 1) = B.at(A.at(i) - 1) + 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 32704)


Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  int n;
  vector<int> data(200001, 0);
  cin >> n;
  int x;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    data.at(x - 1) += 1;
  }
  for (int i = 0; i < n; i++) {
    cout << data.at(i) << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  int n;
  vector<int> data(20001, 0);
  cin >> n;
  int x;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    data.at(x - 1) += 1;
  }
  for (int i = 0; i < n; i++) {
    cout << data.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  long long int n = 0, a = 0;

  cin >> n;

  vector<long int> num(n, 0);
  vector<long int> mem(n + 1, 0);

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  long long int n = 0, a = 0;

  cin >> n;

  vector<long int> num(n, 0);

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

  for (int i = 0; i < n; i++) {
    a = 0;
    for (int k = 0; k < n - 1; k++) {
      if (i + 1 == num[k]) {
        a++;
      }
    }
    cout << a << 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> B(N, 0);
  for (int i = 0; i < N - 1; i++) {
    int A;
    cin >> A;
    B.at(A - 1)++;
  }

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

  for (int i = 1; i <= N; i++) {
    int 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>

using namespace std;

const int maxn = 200010;
long long n, m;
int tem, cnt[maxn] = {0};

int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}

inline void write(int x) {
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top)
    putchar(sta[--top] + 48);
}

int main() {
  n = read();
  m = n;
  n--;
  while (n--) {
    tem = read();
    cnt[tem]++;
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\\n", cnt[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100010;
long long n, m;
int tem, cnt[maxn] = {0};

int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}

inline void write(int x) {
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top)
    putchar(sta[--top] + 48);
}

int main() {
  n = read();
  m = n;
  n--;
  while (n--) {
    tem = read();
    cnt[tem]++;
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\\n", cnt[i]);
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

// Bismillahir Rahmanir Rahim
// AtCoder-c

#include <bits/stdc++.h>
using namespace std;
int a[200010];
int ans[200010];

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

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

Error: TLE

Fixed submission:

// Bismillahir Rahmanir Rahim
// AtCoder-c

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

int countOccurrences(int arr[], int n, int x) {
  int res = 0;
  for (int i = 0; i < n; i++)
    if (x == arr[i])
      res++;
  return res;
}
int main() {

  int n;
  cin >> n;
  int x = n;
  int arr[n + 5];
  for (int i = 1; i < n; ++i)
    cin >> arr[i];
  for (int i = 1; i < n; ++i)
    cout << countOccurrences(arr, x, i) << endl;

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

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
  return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1;
}

long perm(int N, int K) {
  long x = 1;
  for (int i = 1; i <= K; i++)
    x = x * (N - i + 1) % MOD;
  return x % MOD;
}

long comb(int N, int K) {
  long x = 1, y = 1;
  for (int i = 1; i <= K; i++) {
    x = x * (N - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * power(y, MOD - 2) % MOD;
}

bool isprime(int n) {
  if (n < 2)
    return false;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0)
      return false;
  }
  return true;
}

void dfs(const vector<vector<int>> &G, int v, vector<int> &seen) {
  seen[v] = true;

  for (int next_v : G[v]) {
    if (seen[next_v])
      continue;
    dfs(G, next_v, seen);
  }
}

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

int main() {

  int n, tmp;
  cin >> n;
  vector<int> a(n);
  for (int i = 2; i <= n; i++) {
    cin >> tmp;
    a[tmp - 1]++;
  }

  for (int i : a) {
    cout << i << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
  return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1;
}

long perm(int N, int K) {
  long x = 1;
  for (int i = 1; i <= K; i++)
    x = x * (N - i + 1) % MOD;
  return x % MOD;
}

long comb(int N, int K) {
  long x = 1, y = 1;
  for (int i = 1; i <= K; i++) {
    x = x * (N - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * power(y, MOD - 2) % MOD;
}

bool isprime(int n) {
  if (n < 2)
    return false;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0)
      return false;
  }
  return true;
}

void dfs(const vector<vector<int>> &G, int v, vector<int> &seen) {
  seen[v] = true;

  for (int next_v : G[v]) {
    if (seen[next_v])
      continue;
    dfs(G, next_v, seen);
  }
}

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

int main() {

  int n, tmp, cnt;
  cin >> n;
  vector<int> a;
  for (int i = 2; i <= n; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }

  for (int i = 1; i <= n; i++) {
    cnt = 0;
    for (int j : a) {
      if (j == i)
        cnt++;
    }
    cout << cnt << 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), Ajo(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    Ajo.at(A.at(i) - 1)++;
  }

  /*for (int i = 0; i < N;i++)
  {
      for (int j = 0; j < N-1;j++)
      {
          if(A.at(j)==i+1)
          {
              Ajo.at(i)++;
          }
      }
  }*/
  for (int i = 0; i < N; i++) {
    cout << Ajo.at(i) << endl;
  }
}


Error: TLE

Fixed submission:

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

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

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

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

int main() {

  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int N; // 社員の人数
  int c, sum = 0;

  cin >> N;

  int A[N];

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

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


Error: TLE

Fixed submission:

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

int main() {

  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int N; // 社員の人数
  int sum = 0;

  cin >> N;

  int A[N - 1];
  int B[N];

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

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

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

int a[200005];
int ans[200005];

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

  int n;
  cin >> n;
  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] << " ";

  cout << "\\n";

  return 0;
}

Error: WA

Fixed submission:

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

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

  int n, indx, cnt, i;
  cin >> n;
  int a[n + 5];
  int ans[n + 5];
  for (i = 2; i <= n; i++) {
    cin >> a[i];
  }
  indx = 1;
  cnt = 0;
  for (i = 2; i <= n;) {
    if (a[i] == indx) {
      i++;
      cnt++;
    } else {
      ans[indx] = cnt;
      indx++;
      cnt = 0;
    }
  }
  ans[indx] = cnt;
  for (i = indx + 1; i <= n; i++)
    ans[i] = 0;
  for (i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << "\\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> A(N - 1);

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

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

  int num = 0;
  for (int i = 0; i < N - 1; i++) {
    num = A.at(i);
    count.at(num - 1)++;
  }

  for (int i = 0; i < N; i++) {
    cout << count.at(i) << 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);
  }

  for (int i = 0; i < N; i++) {
    cout << count(A.begin(), A.end(), i + 1) << endl;
  }

  return 0;
}