Problem p02707 (C++)

Buggy submission (status: Runtime Error):
// naveen mall
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define vec vector
#define int long long int
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(a, i) for (auto i : a)
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v, n)                                                           \
  for (int i = 0; i < n; i++) {                                                \
    int arb;                                                                   \
    cin >> arb;                                                                \
    v.pb(arb);                                                                 \
  }
#define inset(s, n)                                                            \
  fl(i, 0, n) {                                                                \
    int aset;                                                                  \
    cin >> aset;                                                               \
    s.insert(aset);                                                            \
  }
#define display(c)                                                             \
  trav(c, i) cout << i << " ";                                                 \
  cout << "\n";
#define F first
#define S second
#define pii pair<int, int>
#define PB pop_back
#define endl "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }
template <typename T, typename... Args> T sum(T a, Args... args) {
  return a + sum(args...);
}

vec<int> v[20000 + 5];

void solve() {
  int n;
  cin >> n;
  rep(i, 2, n + 1) {
    int a;
    cin >> a;
    v[a].pb(i);
  }
  rep(i, 1, n + 1) cout << sz(v[i]) << endl;
}
signed main() {
  fast int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}


Fixed submission:
// naveen mall
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define vec vector
#define int long long int
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(a, i) for (auto i : a)
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v, n)                                                           \
  for (int i = 0; i < n; i++) {                                                \
    int arb;                                                                   \
    cin >> arb;                                                                \
    v.pb(arb);                                                                 \
  }
#define inset(s, n)                                                            \
  fl(i, 0, n) {                                                                \
    int aset;                                                                  \
    cin >> aset;                                                               \
    s.insert(aset);                                                            \
  }
#define display(c)                                                             \
  trav(c, i) cout << i << " ";                                                 \
  cout << "\n";
#define F first
#define S second
#define pii pair<int, int>
#define PB pop_back
#define endl "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }
template <typename T, typename... Args> T sum(T a, Args... args) {
  return a + sum(args...);
}

vec<int> v[200000 + 5];

void solve() {
  int n;
  cin >> n;
  rep(i, 2, n + 1) {
    int a;
    cin >> a;
    v[a].pb(i);
  }
  rep(i, 1, n + 1) cout << sz(v[i]) << endl;
}
signed main() {
  fast int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}