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

#include <bits/stdc++.h>

#define ll long long
#define endl '\\n'

using namespace std;

int main() {
  ll n, i;
  cin >> n;
  vector<ll> v(n);
  vector<ll> sub(n);

  ios::sync_with_stdio(false);

  for (i = 1; i < n; i++) {
    cin >> v[i];
    sub[v[i] - 1] += 1;
  }

  for (i = 0; i < n; i++) {
    cout << sub[i] << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define endl '\\n'

using namespace std;

// Returns the index of n if it is in the vector, or -1 case don't
ll bsearch(int n, int vector[], int begin, int end) {
  int l = begin, r = end;
  int mid;

  while (l <= r) {
    mid = (l + r) / 2;

    if (vector[mid] > n) {
      r = mid - 1;
    }

    else if (vector[mid] < n) {
      l = mid + 1;
    }

    else {
      return mid;
    }
  }

  return -1;
}

ll bsearch(ll n, vector<ll> &array, ll begin, ll end) {
  int l = begin, r = end;
  int mid;

  while (l <= r) {
    mid = (l + r) / 2;

    if (array[mid] > n) {
      r = mid - 1;
    }

    else if (array[mid] < n) {
      l = mid + 1;
    }

    else {
      return mid;
    }
  }

  return -1;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  ll i;

  //    ios::sync_with_stdio(false);

  for (ll i = 1; i < n; i++) {
    cin >> v[i];
  }

  vector<ll> sub(n);

  // N == 1;
  for (i = 1; v[i] == 1; i++) {
    sub[0] += 1;
  }

  for (; i < n; i++) {
    sub[bsearch(v[i] - 1, v, 0, i - 1)] += 1;
  }

  for (i = 0; i < n; i++) {
    cout << sub[i] << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
using namespace std;

int main() {
  ll N, count = 1;
  cin >> N;
  vector<ll> A(N - 1, 0);
  vector<ll> A_count(N + 1, 0);
  rep(i, N - 1) cin >> A[i];
  sort(A.begin(), A.end());
  rep(j, N - 1) {
    if (A[j] == count)
      A_count[count]++;
    else {
      j--;
      count++;
    }
  }
  for (int k = 1; k < N + 1; k++)
    cout << A_count[k] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N + 1);
  vector<ll> A_count(N + 1, 0);
  for (ll j = 2; j < N + 1; j++)
    cin >> A[j];
  for (ll i = 2; i < N + 1; i++) {
    for (ll k = 1; k < i; k++) {
      if (A[i] == k)
        A_count[k]++;
    }
  }
  for (ll v = 1; v < N + 1; v++)
    cout << A_count[v] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n;
  int a[200005];

  int sum[200005];

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  int a[200000];

  int sum[200000];

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

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

  for (int i = 0; i < n; i++) {
    cout << sum[i] << endl;
    ;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  q = n;
  int t;
  map<int, int> dd;
  n--;
  while (n--) {
    cin >> t;
    dd[t]++;
  }
  for (int i = 1; i <= q; i++) {
    cout << dd[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)

int a[200001] = {};
int main() {
  int n;
  cin >> n;
  repe(i, 2, n) {
    int x;
    cin >> x;
    a[x]++;
  }
  repe(i, 1, n) { cout << a[i] << endl; }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)

int a[100001] = {};
int main() {
  int n;
  cin >> n;
  repe(i, 2, n) {
    int x;
    cin >> x;
    a[x]++;
  }
  repe(i, 1, n) { cout << a[i] << endl; }

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

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

#define int long long
#define ll long long

#define mod 1000000007
#define inf 1000000000000000
#define infty 1000000000000000000LL
#define md 998244353
#define PI acos(-1.0)
#define endl "\\n"
#define rr return
#define br cout << "\\n";
long long prime[1000000];

void sieve() {
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i < 1000000; i++)
    prime[i] = 1;

  for (int i = 2; i * i < 1000000; i++)
    if (prime[i] == 1)
      for (int j = i * i; j < 1000000; j += i)
        prime[j] = 0;
}

bool isPrime(int n) {
  if (n <= 1)
    return false;
  for (ll i = 2; i <= floor(sqrt(n)); i++)
    if (n % i == 0)
      return false;

  return true;
}

int factorial(int n) {
  int f = 1;
  for (int i = 1; i <= n; i++)
    f = (f * i) % mod;
  return f;
}

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

int lcm(int a, int b) { return (a / gcd(a, b)) * b; }

int fastExponentiation(int n, int x, int modulo) {
  int res = 1;
  while (x > 0) {
    if (x & 1)
      res = (res * n) % modulo;
    x = x >> 1;
    n = (n * n) % modulo;
  }
  return res;
}

int power(int n, int p) {
  if (p == 0)
    return 1;

  int res = power((n * n) % mod, p / 2);
  if (p % 2 == 1)
    res = (n * res) % mod;

  return res;
}

bool isPowerOfTwo(int n) { return n && (!(n & (n - 1))); }

bool isSet(int n, int i) {
  // To check if ith bit is set or not in binary representation of n
  return n & (1 << i);
}

bool valid_coordinate(ll x, ll y, ll n, ll m) {
  if (x < 0 || y < 0)
    return false;

  else if (x >= n || y >= m)
    return false;

  else
    return true;
}

int sod(int n) {
  int sum = 0;
  while (n) {
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}

void solve() {
  int n;
  cin >> n;
  int arr[n], brr[n + 1];
  for (int i = 1; i <= n; i++)
    brr[i] = 0;

  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
    brr[arr[i]]++;
  }
  for (int i = 1; i <= n; i++)
    cout << brr[i] << endl;
}

int32_t main() {

  // int t; cin>>t; while(t--)
  solve();

  return 0;
}

Error: TLE

Fixed submission:

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

int find(vector<int> &v, int i, int n) {
  int count = 0;
  for (int j = 0; j < n - 1; j++) {
    if (v[j] > i)
      break;

    if (v[j] == i)
      count += 1;
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n - 1; i++) {
    int j;
    cin >> j;
    v.push_back(j);
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; i++) {
    cout << find(v, i, n) << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a;
  cin >> a;
  int data[a], result[a];
  data[0] = 0;
  for (int i = 1; i < a; i++)
    cin >> data[i];
  for (int i = 0; i < a; i++) {
    result[i] = 0;
    for (int j = 1; j < a; j++) {
      if ((i + 1) == data[j]) {
        result[i] += 1;
      }
    }
  }
  for (int i = 0; i < a; i++) {
    cout << result[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);

int son[N];

int main(int argc, char **args) {
  // freopen("in.txt", "r", stdin);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int fa;
    scanf("%d", &fa);
    son[fa]++;
  }

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


Error: 0

Fixed submission:

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

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);

int son[N];

int main(int argc, char **args) {
  // freopen("in.txt", "r", stdin);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int fa;
    scanf("%d", &fa);
    son[fa]++;
  }

  for (int i = 1; i <= n; i++) {
    printf("%d\\n", son[i]);
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, A;
  cin >> N;
  vector<int> ans(N, 0);

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

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

Error: 0

Fixed submission:

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

int main() {
  int N, A, i = 1, j = 1;
  int count = 0;
  cin >> N >> A;
  vector<int> ans(N, 0);

  while (i < N) {
    if (j == A) {
      count++;
      cin >> A;
      i++;
    } else {
      ans.at(j - 1) = count;
      count = 0;
      j++;
    }
  }
  ans.at(j - 1) = count;

  for (int i = 0; i < N; i++) {
    cout << ans.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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

Error: TLE

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;
  cin >> n;
  vector<int> a(n);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    int temp = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == i) {
        temp++;
      }
    }
    cout << temp << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int n;
const int N = 212345;
vvi g(N);
vi dp(N);

void dfs(int u = 1, int p = 1) {
  trav(v, g[u]) {
    if (v == p)
      continue;
    dfs(v, u);
    dp[u] += dp[v] + 1;
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  cin >> n;
  vi ans(n + 1);
  rep(i, 2, n + 1) {
    int s;
    cin >> s;
    ++ans[s];
  }

  rep(i, 1, n + 1) cout << ans[i] << '\\n';
}

Error: 0

Fixed submission:

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int n;
const int N = 212345;
vvi g(N);
vi dp(N);

void dfs(int u = 1, int p = 1) {
  trav(v, g[u]) {
    if (v == p)
      continue;
    dfs(v, u);
    dp[u] += dp[v] + 1;
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  vi ans(n + 1);
  cin >> n;
  rep(i, 2, n + 1) {
    int s;
    cin >> s;
    ++ans[s];
  }

  rep(i, 1, n + 1) cout << ans[i] << '\\n';
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> boss(n);
  vector<ll> count(n);
  boss[0] = 0;
  rep(i, n - 1) cin >> boss[i + 1];
  rep(i, n) a[i] = i + 1;
  sort(all(boss));
  rep(i, n) {
    auto itr1 = upper_bound(all(boss), a[i]);
    auto itr2 = lower_bound(all(boss), a[i]);
    count[i] = itr1 - itr2;
  }

  rep(i, n) cout << count[i] << endl;
}

Error: TLE

Fixed submission:

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

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> boss(n);
  vector<int> count(n);
  boss[0] = 0;
  rep(i, n - 1) cin >> boss[i + 1];
  rep(i, n) a[i] = i + 1;
  rep(i, n) {
    rep(j, n) {
      if (a[i] == boss[j])
        count[i]++;
    }
  }
  /*
  rep(i,n){
      auto itr=upper_bound(all(boss),a[i]);
      count[i]=itr-a.begin();
  }
  */
  // rep(i,n) cout<<a[i]<<' '; cout << endl;
  // rep(i,n) cout << boss[i] << ' '; cout << endl;
  rep(i, n) cout << count[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;

#define read(x) scanf("%d", &x)
#define readl(x) scanf("%lld", &x)
#define ll long long
#define ull unsigned long long

int n, l;
int b[200005] = {0};

int main() {
  read(n);
  for (int i = 2; i <= n; i++)
    read(l), b[l]++;
  for (int i = 1; i <= n; i++)
    printf("%d\\n", b[i]);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;

#define read(x) scanf("%d", &x)
#define readl(x) scanf("%lld", &x)
#define ll long long
#define ull unsigned long long

int n, l;
int b[100005] = {0};

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int j = 1;
  for (int i = 1; i < n + 1; i++) {
    int cnt = 0;
    while (a[j] == i && j < n) {
      cnt++;
      j++;
    }
    cout << cnt << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

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: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int arr[100];
  int cnta[100] = {0};
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    int a = arr[i];
    if (a == 0)
      continue;
    for (int j = 0; j < n - 1; j++) {
      if (arr[j] != 0) {
        if (arr[j] == a) {
          cnt++;
          arr[j] = 0;
        }
      }
    }
    if (a != 0)
      cnta[a - 1] = cnt;
  }
  for (int i = 0; i < n; i++) {
    cout << cnta[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

// 素数判定
bool isPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}

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

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define PI 3.14159265359

// 素数判定
bool isPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  rep(i, n - 1) cin >> a[i];
  vector<int> ans(n);
  rep(i, n) ans[a[i] - 1]++;
  rep(i, n) cout << ans[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct node {
  int parent;
  int *nect;
};

int main() {

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

  int n;
  cin >> n;

  vector<int> par(n + 1);
  vector<int> num(n + 1);
  par[0] = 0;
  par[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    int tmp;
    cin >> tmp;
    par[i] = tmp;
    num[par[i]]++;
  }
  /*
  for(int i=1;i<n+1;i++){
          for(int j=i+1;j<n+1;j++){
                  if(par[j]==i)
                          num[par[j]]++;
          }
          cout<<num[i];
          if(i!=n) cout<<"\\n";
  }
  */
  for (int i = 1; i < n + 1; i++) {
    cout << num[i];
    if (i != n)
      cout << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

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

struct node {
  int parent;
  int *nect;
};

int main() {

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

  int n;
  cin >> n;

  vector<int> par(n + 1);
  par[0] = 0;
  par[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    int tmp;
    cin >> tmp;
    par[i] = tmp;
  }
  vector<int> num(n + 1);
  for (int i = 1; i < n + 1; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      if (par[j] == i)
        num[par[j]]++;
    }
    cout << num[i];
    if (i != n)
      cout << "\\n";
  }

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

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
typedef long long int ll;
using namespace std;
#define maxN 200007

int n;

void solve() {
  int temp[maxN] = {};
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    temp[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << temp[i] << endl;
  }
}

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

  cin >> n;
  solve();
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
typedef long long int ll;
using namespace std;
#define maxN 200007

int n;

int solve() {
  int temp[maxN] = {};
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    temp[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << temp[i] << endl;
  }
}

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

  cin >> n;
  solve();
}
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) < (n); (i)++)
int main() {
  int N;
  cin >> N;
  int64_t ans = 0;
  int now = 0;
  vector<int> vec(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> now;
    vec.at(now - 1)++;
  }
  rep(i, N) { cout << vec.at(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;
  int64_t ans = 0;
  int now = 0;
  vector<int> vec(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  rep(i, N) {
    now = 0;
    rep(j, N - 1) {
      if (i + 1 == vec.at(j)) {
        now++;
      }
    }
    cout << now << endl;
  }
}