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

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

int main() {
  int N, hito, count;

  std::cin >> N;
  std::vector<int> syain(N);
  std::vector<int> numbers(N, 0);
  syain[0] = 0;

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

  for (int i = 1; i < N; i++) {
    numbers[syain[i] - 1]++;
  }

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

Error: 0

Fixed submission:

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

int main() {
  int N, hito, count;

  std::cin >> N;
  vector<int> syain(N), numbers(N);
  syain[0] = 0;

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

  for (int i = 0; i < N; i++) {
    hito = i + 1;
    count = 0;
    for (int j = i + 2; j < N + 1; j++) {
      // std::cout << hito << " " << syain[j] << "\\n";
      if (hito == syain[j]) {
        count++;
      }
    }
    printf("%d\\n", count);
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  map<ll, ll> arr;
  ll temp;
  for (ll i = 0; i < n - 1; i++) {
    cin >> temp;
    auto j = arr.find(temp);
    if (j == arr.end())
      arr.insert(make_pair(temp, 1));
    else
      j->second++;
  }

  for (ll i = 1; i <= n; i++) {
    auto j = arr.find(i);
    if (j == arr.end())
      cout << 0 << endl;
    else
      cout << j->second << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> arr(n - 1);
  for (auto &i : arr)
    cin >> i;

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

#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)

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

  rep(i, N) cout << B[i + 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 0; i < N - 1; i++) {
    int idx;
    cin >> idx;
    A[idx - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
  vector<int> vi;
  vector<int> vi2;
  bool apenas1 = true;
  int apareceu1 = 1;
  int n, a;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    vi.pb(a);
    vi2.pb(0);
  }
  vi.pb(n);
  vi2.pb(0);
  for (int i = 0; i < n - 1; i++) {
    if (vi[i] != 1) {
      apenas1 = false;
      break;
    }
  }
  if (apenas1) {
    vi2[0] = n - 1;
    for (int i = 0; i < n - 1; i++) {
      cout << vi2[i] << endl;
    }
    cout << 0 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (vi[i] + 1 == vi[j + 1]) {
          vi2[i]++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << vi2[i] << endl;
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  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++) {
    B.at(A.at(i) - 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);
  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++) {
    B.at(i) = 0;
    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 <array>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n], count[n + 1];
  for (int i = 0; i < n + 1; i++) {
    count[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
    count[arr[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << count[i] << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
const int maxn = 2e5 + 5;
int cnt[maxn];

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

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

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


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
const int maxn = 1e5 + 5;
int cnt[maxn];

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

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

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

#include <bits/stdc++.h>
#include <math.h>
#include <string>
#define M_PI 3.14159265358979323846
using namespace std;
int main() {
  int n, m, i, s, a[200001], b[200001];
  cin >> n;

  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  for (i = 1; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#include <string>
#define M_PI 3.14159265358979323846
using namespace std;
int main() {
  int n, m, i, s, a[100000], b[100000];
  cin >> n;
  i = 0;
  s = 0;
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  for (i = 1; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }

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

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


Error: WA

Fixed submission:

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

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

int main() {
  cin >> N;
  for (int i = 1; i < N; i++)
    cin >> a[i];
  map<int, int> mp;
  for (int i = 1; i < N; i++) {
    mp[i] = 0;
  }
  for (int i = 1; i < N; i++) {
    mp[a[i]]++;
  }
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    cout << itr->second << endl;
  }
  cout << 0 << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  cin >> N;
  for (int i = 1; i < N; i++)
    cin >> a[i];
  map<int, int> mp;
  for (int i = 1; i < N; i++) {
    mp[i] = 0;
  }
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    for (int i = 1; i < N; i++) {
      if (a[i] == itr->first) {
        itr->second++;
      }
    }
  }
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    cout << itr->second << endl;
  }
  cout << 0 << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
void func(vector<int> k) {
  vector<int> k1(k.size());
  for (int i : k) {
    k1[i - 1]++;
  }
  for (int i : k1) {
    cout << i << endl;
  }
  cout << "0" << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> k(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> k[i];
  }
  func(k);
}

Error: -6
double free or corruption (out)


Fixed submission:

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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> vc(n);
  vector<ll> cnt(n);
  for (int i = 0; i < n; i++) {
    cnt[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> vc[i];
    cnt[vc[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << cnt[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> vc(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> vc[i];
  }
  for (int i = 0; i < n; i++) {
    ll cnt = 0;
    for (int j = 0; j < n; j++) {
      if (i + 1 == vc[j]) {
        cnt++;
      }
    }
    cout << cnt << 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;

  int a;
  vector<int> num(N, 0);
  rep(i, N - 1) {
    cin >> a;
    num[a - 1]++;
  }

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


Error: -6
double free or corruption (out)


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);
  rep(i, N - 1) cin >> A[i + 1];

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

  rep(i, N) cout << num[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

//**PEACE BE UPON YOU**
// AZMAYEN FAYEK SABIL
// IUT CSE SWE-19

#include <bits/stdc++.h>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main()

{
  int n;
  cin >> n;

  int a[200005];
  int c[200005] = {0};

  int i;

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

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

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

  return 0;
}


Error: 0

Fixed submission:

//**PEACE BE UPON YOU**
// AZMAYEN FAYEK SABIL
// IUT CSE SWE-19

#include <bits/stdc++.h>
#include <iostream>

#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main()

{
  int n;
  cin >> n;

  int a[100005];
  int c[100005] = {0};

  int i;

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

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

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

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


#include <bits/stdc++.h>
#define mes(a, b) memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 2e5 + 20;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int has[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v;
    cin >> v;
    has[v]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\\n", has[i]);
}

Error: 0

Fixed submission:


#include <bits/stdc++.h>
#define mes(a, b) memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e5 + 20;
const int maxm = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
int has[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v;
    cin >> v;
    has[v]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\\n", has[i]);
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int a[n - 1], count = 0, x = 0;
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  sort(a, a + n - 1);
  for (int i = 1; i <= n; i++) {
    while (a[x] == i && x < n - 1) {
      count++;
      x++;
    }
    cout << count << endl;
    count = 0;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

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

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


Error: 0

Fixed submission:

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

#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<int> A(N - 1);
  vector<int> B(N, 0);
  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 5)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N, 0);
  for (int i = 0; i < N; 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;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

const int mN = 200200;
int c[mN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 2, a; i <= n; i++)
    cin >> a, c[a]++;
  for (int i = 1; i <= n; i++)
    cout << c[i] << " ";
}

Error: WA

Fixed submission:

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

const int mN = 100100;
int c[mN];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 2, a; i <= n; i++)
    cin >> a, c[a]++;
  for (int i = 1; i <= n; i++)
    cout << c[i] << " ";
}
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, 0);
  for (int i = 0; i < N - 1; i++)
    cin >> A.at(i);
  vector<int> ans(N);
  for (int i = 0; i < N - 1; i++)
    ++ans.at(A.at(i) - 1);
  for (int i = 0; i < N; i++)
    cout << ans.at(i) << endl;

  return 0;
}

Error: TLE

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);
  }

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

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

#include <iostream>
using namespace std;

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

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

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

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

  for (int i = 1; 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<long long> A(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> A.at(i);
  }

  vector<long long> B(n, 0);

  for (int i = 0; i < n - 1; i++) {
    B.at(A.at(i) - 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<long long> A(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> A.at(i);
  }

  vector<long long> B(n, 0);

  for (int i = 0; i < n - 1; i++) {
    for (int j = 1; j < n; j++) {
      if (A.at(i) == j) {
        B.at(j - 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;

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

  vector<long long> A(n - 1);
  vector<long long> B(n, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> A.at(i);
    B.at(A.at(i) - 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<long long> a(n), ans(n, 0);
  for (int i = 2; i <= n; i++)
    cin >> a.at(i);
  for (int i = 2; i <= n; i++)
    ans.at(a.at(i))++;
  for (int i = 1; i <= n; i++)
    cout << ans.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> counter(n);
  vector<int> number(n - 1);

  for (int i = 0; i < n; i++) {
    counter.at(i) = 0;
  }

  for (int i = 0; i < (n - 1); i++) {
    cin >> number.at(i);
    counter.at(number.at(i) - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << counter.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> number(n - 1);

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

  vector<int> counter(n);

  for (int i = 0; i < n; i++) {
    counter.at(i) = 0;
  }

  for (int i = 0; i < (n - 1); i++) {
    for (int j = 0; j < (i + 1); j++) {
      if (number.at(i) == j + 1)
        counter.at(j)++;
    }
  }

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