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

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n;
  int counter[n] = {0};
  vector<int> arr(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
    counter[arr[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {

    cout << counter[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n;
  vector<int> arr(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= n; i++) {
    int c = count(arr.begin(), arr.end(), i);
    cout << c << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define INF 99999999
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int N;

  cin >> N;

  vector<int> s(N + 1);
  vector<int> res(N + 1);

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

    res[s[i]] += 1;
  }

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

Error: TLE

Fixed submission:

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

#define ll long long
#define INF 99999999
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int N;

  cin >> N;

  //    std::map<int, int> res;

  //    for( int i = 0; i < N; i++ )
  //    {
  //        if ( i == 0 )
  //        {
  //            continue;
  //        }

  //        cin >> res[i];

  //        for( int j = 1; j <= N; j++ )
  //        {
  //            if( j == res[i] )
  //            {
  //                res[j] += 1;
  //                break;
  //            }
  //        }
  //    }

  vector<int> s(N + 1);
  vector<int> res(N + 1);

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

    for (int j = 1; j <= N; j++) {
      if (j == s[i]) {
        res[j] += 1;
        break;
      }
    }
  }

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

#include <iostream>
using namespace std;

int main() {
  int number;
  int boss[200010] = {0}, count[200010] = {0};

  std::cin >> number;

  for (int i = 2; i <= number; i++) {
    std::cin >> boss[i];
  }

  for (int i = 2; i <= number; i++) {
    count[boss[i]]++;
  }

  for (int i = 1; i <= number; i++) {
    std::cout << count[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int number;
  int boss[200010], count[200010];

  std::cin >> number;

  for (int i = 0; i < number - 1; i++) {
    std::cin >> boss[i];
  }

  for (int i = 1; i <= number; i++) {
    for (int j = i - 1; j < number - 1; j++) {
      if (boss[j] == i)
        count[i]++;
    }
    std::cout << count[i] << endl;
  }

  // std::cout << <<endl   ;

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

// Tariquzzaman Faisal
//_Faisal101_
// IUT_CSE'19
// 190041101

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
#define mp make_pair
#define pb push_back
#define pb push_back
#define fileOut freopen("out.txt", "w", stdout)
#define fileIn freopen("in.txt", "r", stdout)
#define testcases                                                              \\
  ll tc, t;                                                                    \\
  cin >> tc;                                                                   \\
  for (t = 1; t <= tc; t++)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define pi acos(-1.0)
#define ll long long

using namespace std;

ll ara[200010];

int main() {

  ll n, temp;
  cin >> n;
  for (ll i = 0; i < n - 1; i++) {
    cin >> temp;
    ara[temp]++;
  }
  for (ll i = 1; i <= n; i++) {
    cout << ara[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

// Tariquzzaman Faisal
//_Faisal101_
// IUT_CSE'19
// 190041101

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
#define mp make_pair
#define pb push_back
#define pb push_back
#define fileOut freopen("out.txt", "w", stdout)
#define fileIn freopen("in.txt", "r", stdout)
#define testcases                                                              \\
  ll tc, t;                                                                    \\
  cin >> tc;                                                                   \\
  for (t = 1; t <= tc; t++)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define pi acos(-1.0)
#define ll long long

using namespace std;

ll ara[100010];

int main() {

  ll n, temp;
  cin >> n;
  for (ll i = 0; i < n - 1; i++) {
    cin >> temp;
    ara[temp]++;
  }
  for (ll i = 0; i < n; i++) {
    cout << ara[i + 1] << endl;
    ara[i + 1] = 0;
  }

  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> assistant(N);

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

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

  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<int> boss(N);
  vector<int> assistant(N);

  boss.at(0) = -1;

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

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

    int assistantNum = 0;

    for (int j = 0; j < N; j++) {
      if (boss.at(j) == i + 1)
        assistantNum++;
    }
    assistant.at(i) = assistantNum;
  }

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

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

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

Error: 0

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, c[1000005], x;
  cin >> t;
  for (i = 1; i <= t - 1; i++) {
    cin >> x;
    c[x]++;
  }
  for (int i = 1; i <= t; i++)
    cout << c[i] << endl;
}


Error: 0

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

const int N = 250000;
const int M = 500;
const int MOD = 1e9 + 7;
const int alpha = 26;
const double PI = acos(-1);
ll n, k;
ll ans = 0;
ll a[N];
ll b[N];

signed main() {
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#endif // ONLINE_JUDGE
  cin >> n;
  for (int i = 1; i < n; i++)
    cin >> k, a[k]++;
  for (int i = 1; i <= n; i++)
    cout << a[i] << "\\n";
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

const int N = 150000;
const int M = 500;
const int MOD = 1e9 + 7;
const int alpha = 26;
const double PI = acos(-1);
ll n, k;
ll ans = 0;
ll a[N];
ll b[N];

signed main() {
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#endif // ONLINE_JUDGE
  cin >> n;
  for (int i = 1; i < n; i++)
    cin >> k, a[k]++;
  for (int i = 1; i <= n; i++)
    cout << a[i] << "\\n";
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

/**
 *    author:  musasi
 *    created: 19.04.2020 21:29:30
 **/

#include <bits/stdc++.h>

using namespace std;
#define rep2(x, from, to) for (long long(x) = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
#define MOD 10000007 // 10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define ASSERT(expr...) assert((expr))
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<ll, PP> PPP;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int n;
int ans[200006];
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<int> a(n - 1);
  rep(i, n - 1) {
    cin >> a[i];
    ans[a[i] - 1]++;
  }
  rep(i, n) cout << ans[i] << endl;

  return 0;
}

Error: 0

Fixed submission:

/**
 *    author:  musasi
 *    created: 19.04.2020 21:29:30
 **/

#include <bits/stdc++.h>

using namespace std;
#define rep2(x, from, to) for (long long(x) = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
#define MOD 10000007 // 10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define ASSERT(expr...) assert((expr))
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<ll, PP> PPP;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int n;
int ans[100006];
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<int> a(n - 1);
  rep(i, n - 1) {
    cin >> a[i];
    ans[a[i] - 1]++;
  }
  rep(i, n) cout << ans[i] << endl;

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

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

  int tmp;

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

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n - 1);
  int sum = 0;
  for (int i = 0; i < n - 1; ++i)
    cin >> vec[i];

  for (int j = 1; j <= n; j++) {
    sum = count(vec.begin(), vec.end(), j);
    cout << sum << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <map>
#include <math.h>
#include <set>
#include <string>

#define INF 1000000000000
#define MOD 1000000007 // 10^9+7:合同式の法

using namespace std;
typedef long long ll;

// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

int main() {
  ll N;
  cin >> N;
  vector<ll> jousi(N), buka(N);

  for (ll i = 0; i < N - 1; i++) {
    cin >> buka.at(i);
    jousi.at(i) = 0;
  }

  for (ll i = 0; i < N - 1; i++) {
    jousi[buka[i] - 1]++;
  }

  for (ll i = 0; i < N; i++) {
    cout << jousi[i] << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N, sum;
  cin >> N;
  vector<int> buka(N - 1);

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

  for (int i = 1; i < N; i++) {
    sum = 0;
    for (int j = 0; j < N - 1; j++) {
      if (i == buka.at(j))
        sum++;
    }
    cout << sum << endl;
  }
  cout << 0 << endl;
}
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];
  vector<int> ans(N + 1, 0);
  for (int i = 2; i <= N; i++) {
    cin >> A[i];
    ans[A[i]]++;
  }
  for (int i = 1; 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);
  A[0] = 0;
  for (int i = 1; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    size_t cnt = count(A.begin() + i + 1, A.end(), i + 1);
    cout << cnt << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  int boss[N + 1] = {0};

  int input;
  for (int i = 1; i < N; i++) {
    cin >> input;
    boss[input] = boss[input] + 1;
  }

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

Error: TLE

Fixed submission:

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

int main() {
  int N, tmp;
  cin >> N;
  vector<int> A;
  for (int i = 0; i < N - 1; i++) {
    cin >> tmp;
    A.push_back(tmp);
  }
  for (int i = 1; i < N + 1; i++) {
    size_t n_count = count(A.begin(), A.end(), i);
    cout << n_count << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a;
  vector<int> v1(200010, 0);
  for (int i = 1; i < N; i++) {
    cin >> a;
    v1.at(a - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << v1.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v1(200010, 0);
  vector<int> v2(200010, 0);
  for (int i = 0; i < N; i++) {
    cin >> v1.at(i);
    for (int j = 1; j < i + 2; j++) {
      if (v1.at(i) == j) {
        v2.at(j - 1)++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << v2.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //    int t;
  //    cin>>t;
  int x = 1;
  //    while(t--) {
  int n;
  cin >> n;
  int a[n - 1];
  fo(i, n - 1) { cin >> a[i]; }
  int arr[200001] = {0};
  for (int o : a) {
    arr[o]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << endl;
  }

  x++;
  //    }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //    int t;
  //    cin>>t;
  int x = 1;
  //    while(t--) {
  int n;
  cin >> n;
  int a[n - 1];
  fo(i, n - 1) { cin >> a[i]; }
  int arr[100001] = {0};
  for (int o : a) {
    arr[o]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << arr[i] << endl;
  }

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

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

int main() {
  long long n, a[300000];
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }

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

Error: TLE

Fixed submission:

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

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

  int count = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < n; j++) {
      if (i == a[j])
        count++;
    }
    cout << count << endl;
    count = 0;
  }
}
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] = {0};
  int ans[N] = {0};

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

  for (int i = 1; i < N; 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);
  a.at(0) = 0;
  int n_count;

  for (int i = 0; i < N - 1; i++) {
    cin >> a.at(i + 1);
  }
  for (int i = 0; i < N; i++) {
    n_count = std::count(a.begin(), a.end(), i + 1);
    cout << n_count << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};

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


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};

int main() {
  ll n;
  cin >> n;
  ll a[n], b[n + 1];
  for (ll i = 0; i < n + 1; i++)
    b[i] = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (ll i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int i, j, k, count1 = 0, count2 = 0;
void ABC161();
void ABC162();
void ABC163();
void ABC164();

int main() { ABC163(); }

void ABC163() {
  int n, x;
  cin >> n;
  vector<int> vec(n, 0);
  for (i = 0; i < n - 1; i++) {
    cin >> x;
    vec[x - 1]++;
  }
  for (i = 0; i < n; i++) {
    cout << vec[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int i, j, k, count1 = 0, count2 = 0;
void ABC161();
void ABC162();
void ABC163();
void ABC164();

int main() { ABC163(); }

void ABC163() {
  int n;
  cin >> n;
  vector<int> vec(n - 1);
  for (i = 0; i < n; i++) {
    cin >> vec[i];
  }
  for (i = 1; i <= n; i++) {
    cout << count(vec.begin(), vec.end(), i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> a(n, 0);

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

  vector<int> ans(n, 0);
  for (int i = 1; i < n; i++) {
    ans.at(a.at(i) - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> a(n, -1);

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

  for (int i = 1; i <= a.size(); i++) {
    int count = 0;
    for (int j = i; j < a.size(); j++) {
      if (i == a.at(j))
        count++;
    }
    cout << count << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

long long n;

int main() {
  cin >> n;
  int a[n + 1], b[n + 1];

  for (int i = 1; i <= n; i++)
    b[i] = 0;

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

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

  return 0;
}


Error: WA

Fixed submission:

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

long long n;

int main() {
  long long a[n + 1], b[n + 1];
  for (int i = 1; i <= n; i++)
    b[i] = 0;

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

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

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

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


Error: 0

Fixed submission:

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