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

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 1;
int a[N];

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m, sum = 0, res = 0;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum > n)
    cout << "-1\\n";
  else
    cout << n - sum << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int a[1000];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m, res = 0, cnt = 0;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
    n -= a[i];
  }
  cout << max(n, -1);
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#define N_MAX 1000000
#define M_MAX 10000

using namespace std;
long long N, M;
long long A[M_MAX];

void solve() {
  long long sum = 0;
  long long res = 0;
  for (int i = 0; i < M; i++) {
    sum += A[i];
  }
  res = N - sum;
  if (res < 0) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
  return;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  solve();

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#define N_MAX 1000000
#define M_MAX 1000

using namespace std;
long long N, M;
long long A[M_MAX];
void solve() {
  long long sum = 0;
  long long res = 0;
  for (int i = 0; i < M; i++) {
    sum += A[i];
  }
  res = N - sum;
  if (res < 0) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  solve();

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

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
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);
  for (int i = 0; i < n - 1; i++)
    ans[a[i] - 1]++;
  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
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);
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i] == j + 1)
        ans[j]++;
    }
  }
  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() {
  int n;
  cin >> n;
  int a[200010], b[200010];
  // memset(a,0,sizeof(a));
  memset(b, 0, sizeof(b));
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    b[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << endl;
  }
}

Error: WA

Fixed submission:


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

void printfrequency(int arr[], int n) {
  for (int j = 0; j < n; j++)
    arr[j] = arr[j] - 1;

  for (int i = 0; i < n; i++)
    arr[arr[i] % n] = arr[arr[i] % n] + n;

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

  int n;
  cin >> n;
  int a[n - 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n - 1] = 0;
  printfrequency(a, n);
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <map>
#include <string>
#include <vector>
#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);
  rep(i, n - 1) cin >> a[i];
  vector<int> ans(n);
  rep(i, n - 1) ans[a[i] - 1]++;
  rep(i, n) cout << ans[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <map>
#include <string>
#include <vector>
#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) cin >> a[i];
  sort(a.begin(), a.end());
  for (int j = 1; j <= n; j++) {
    int ans = 0;
    rep(i, n) {
      if (a[i] == j)
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
// https://atcoder.jp/contests/abc163/tasks/abc163_c
typedef long long ll;

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

  rep(i, N - 1) {
    int A;
    cin >> A;
    a[A - 1]++;
  }

  // for(auto &i:a) cout << i << endl;
  rep(i, N) cout << a.at(i) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> S(N), a(N);
  rep(i, N - 1) cin >> S.at(i);
  S.insert(S.begin(), 0);

  // rep(i, N) a.at(i) = count(S.begin(), S.end(), i+1);

  rep(i, N) cout << count(S.begin(), S.end(), i + 1) << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define _fastIO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long int
#define pb push_back
#define PI acos(-1)
#define MAX 200005

ll a[MAX];
int main() {

  ll n, x;
  cin >> n;
  n = n - 1;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
  }

  for (ll j = 1; j <= n + 1; j++)
    cout << a[j] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _fastIO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define ll long long int
#define pb push_back
#define PI acos(-1)
#define MAX 100000

ll a[MAX];
int main() {
  map<ll, ll> mp;
  ll n, x;
  cin >> n;
  n = n - 1;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
  }

  for (ll j = 1; j <= n + 1; j++)
    cout << a[j] << 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 - 1);
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++) {
    A.at(i) = 0;
    B.at(i) = 0;
    cin >> A.at(i);
    B.at(A.at(i) - 1) += 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++) {
    A.at(i) = 0;
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    B.at(i) = 0;
    for (int j = 0; j < N - 1; j++) {
      if (i == A.at(j) - 1) {
        B.at(i) += 1;
      } else {
        continue;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << B.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> ans(n + 1, 0);
  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:

#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 = 1; i < n; i++) {
    ans[i - 1] = count(a.begin(), a.end(), i);
  }

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

#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
#define pb push_back

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int arr[n], brr[n + 1] = {0};
  arr[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> arr[i];
    brr[arr[i]]++;
  }
  for (int i = 1; i <= n; i++)
    cout << brr[i] << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
#define pb push_back

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int arr[n];
  arr[0] = -1;
  for (int i = 1; i < n; i++)
    cin >> arr[i];
  for (int i = 1; i <= n; i++)
    cout << count(arr, arr + n, i) << "\\n";

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

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

#define ll long long
#define pb push_back

const int maxn = 2e5 + 20;

vector<int> adj[maxn];

bool visited[maxn];

void dfs(int v) {
  visited[v] = 1;
  for (auto u : adj[v])
    if (!visited[u])
      dfs(u);
}

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

  int n;
  cin >> n;

  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    a--;

    adj[a].pb(i);
  }
  for (int i = 0; i < n; i++) {
    cout << adj[i].size() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long
#define pb push_back

const int maxn = 1e5 + 20;

vector<int> adj[maxn];

bool visited[maxn];

void dfs(int v) {
  visited[v] = 1;
  for (auto u : adj[v])
    if (!visited[u])
      dfs(u);
}

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

  int n;
  cin >> n;

  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    a--;

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

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

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<int> v(n, 0), t(n, 0);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }

  for (long long i = 0; i < n; i++) {
    t[v[i] - 1] += 1;
  }
  for (long long j = 0; j < n; j++) {
    cout << t[j] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int N, a;
  cin >> N;
  int A[N], B[N];
  B[0] = 0;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    B[i] = 0;
  }
  for (int j = 1; j < N; j++) {
    a = A[j] - 1;
    B[a] += 1;
  }
  for (int k = 0; k < N; k++) {
    cout << B[k] << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long int N, a;
  cin >> N;
  int A[N];
  for (long int i = 1; i < N; i++) {
    cin >> A[i];
  }
  for (long int j = 1; j <= N; j++) {
    a = 0;
    for (long int i = 1; i <= N; i++) {
      if (j == A[i]) {
        a += 1;
      }
    }
    cout << a << "\\n";
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;
  cin >> N;

  int ans[200010];

  int A[200010];
  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] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;
  cin >> N;

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

  int members[N + 1];

  for (int j = 1; j <= N; j++) {
    members[j] = 0;

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

      if (j == A[i]) {
        members[j]++;
      }
    }
  }

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

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#define TitansGo                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(v) v.begin(), v.end()
#define YES cout << "YES\\n";
#define NO cout << "NO\\n";
#define ll long long
#define endl "\\n"
#define S second
#define F first
using namespace std;
int frq[200000];
int main() {
  TitansGo int n, a;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a;
    frq[a]++;
  }
  for (int i = 1; i <= n; i++)
    cout << frq[i] << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#define TitansGo                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(v) v.begin(), v.end()
#define YES cout << "YES\\n";
#define NO cout << "NO\\n";
#define ll long long
#define endl "\\n"
#define S second
#define F first
using namespace std;
int frq[50000];
int main() {
  TitansGo int n, a;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a;
    frq[a]++;
  }
  for (int i = 1; i <= n; i++)
    cout << frq[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);
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  vector<int> c(n);

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

  rep(i, n) { printf("%d\\n", c[i]); }

  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);
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  vector<int> c(n);

  rep(i, n) { c[a[i] - 1]++; }

  rep(i, n) { printf("%d\\n", c[i]); }

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

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


Error: -11

Fixed submission:

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

// #pragma GCC optimize(“O2”)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define pi 3.14159265358979323846264338327950254
#define STDIN                                                                  \\
  freopen("in.txt", "r", stdin);                                               \\
  freopen("out.txt", "w", stdout); //************************************

#define ll long long
// #define int ll

const int mod = 100999;
const int N = 3e5 + 10;
int son[N];
int main() {
  // STDIN
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int t;
    cin >> t;
    son[t]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << son[i] << endl;
  }
}


Error: 0

Fixed submission:

// #pragma GCC optimize(“O2”)
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define pi 3.14159265358979323846264338327950254
#define STDIN                                                                  \\
  freopen("in.txt", "r", stdin);                                               \\
  freopen("out.txt", "w", stdout); //************************************

#define ll long long
// #define int ll

const int mod = 100999;
const int N = 1e5 + 10;
int son[N];
int main() {
  // STDIN
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int t;
    cin >> t;
    son[t]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << son[i] << 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];
  for (int i = 0; i < n + 1; i++)
    a[i] = 0;
  int x;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    a[x]++;
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << "\\n";
  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];
  }
  int c;
  for (int i = 0; i < n; i++) {
    c = 0;
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == i + 1)
        c++;
    }
    cout << c << "\\n";
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  vector<int> a(N + 1);

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

  for (int i = 1; i <= N; ++i) {
    cout << a[i] << "\\n";
    // printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  int a[N];

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

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    ans = count(a, a + N - 1, i + 1);
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 2; i <= n; i++) {
    int num;
    cin >> num;
    a.at(num)++;
  }
  for (int i = 1; i <= n; i++) {
    cout << a.at(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 - 1);
  rep(i, n - 1) cin >> a.at(i);
  sort(a.begin(), a.end());
  rep(i, n) {
    if (i < a.back()) {
      cout << count(a.begin(), a.end(), i + 1) << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[50000000];
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    dp[a[i]]++;
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[50000];
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    dp[a[i]]++;
  }

  for (int i = 1; i <= n; i++) {
    cout << dp[i] << endl;
  }
}
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 < (int)(n); i++)
typedef long long ll;
const double pi = 3.14159265358979323846;
int ctoi(const char c) {
  if ('0' <= c && c <= '9')
    return (c - '0');
  return -1;
}
vector<int> input(int n) {
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  return vec;
}
void output(vector<int> vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  return;
}
vector<vector<int>> input(int n, int m) {
  vector<vector<int>> table(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> table.at(i).at(j);
    }
  }
  return table;
}
void output(vector<vector<int>> table) {
  for (int i = 0; i < table.size(); i++) {
    for (int j = 0; j < table.at(0).size(); j++) {
      cout << table.at(i).at(j) << " ";
    }
    cout << endl;
  }
}
long long perm(int n, int r) {
  if (n < r) {
    cout << "error" << endl;
    return 0;
  }
  long long perm = 1;
  for (int i = n; i > n - r; i--) {
    perm *= i;
  }
  return perm;
}
long long comb(int n, int r) {
  if (n < r) {
    cout << "error" << endl;
    return 0;
  }
  long long comb = perm(n, r);
  for (int i = r; i > 0; i--) {
    comb /= i;
  }
  return comb;
}
long long homo(int n, int r) { return comb(n + r - 1, n - 1); }
long long fact(int n) {
  long long fact = 1;
  for (int i = n; i > 0; i--) {
    fact *= i;
  }
  return fact;
}
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool isprime(int n) {
  if (n < 2)
    return false;
  else if (n == 2)
    return true;
  else if (n % 2 == 0)
    return false;

  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
void sayYes(bool f) {
  if (f) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
void sayYES(bool f) {
  if (f) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  cin >> n;
  vector<int> v = input(n - 1);
  rep(i, n - 1) {
    int count = 0;
    rep(j, n - 1) {
      if (i + 1 == v[j]) {
        count++;
      }
    }
    cout << count << endl;
  }
  cout << 0 << endl;
}