Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
// #define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define maxe max_element
#define mine min_element
#define fn(i, x) for (i = 0; i < x; i++)
#define fs(i, s, x) for (i = s; i < x; i++)
#define fr(i, x) for (i = x; i >= 0; i--)
#define fit(itr, s) for (itr = s.begin(); itr != s.end(); itr++)
#define W while
#define pp pair<ll, ll>
#define ppi pair<ll, ll>
#define vl vector<ll>
#define vll vector<pp>
#define vi vector<int>
#define vii vector<ppi>
#define debug(x) cerr << #x << " :: " << x << endl;
#define debug2(x, y)                                                           \
  cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define debug3(x, y, z)                                                        \
  cerr << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z         \
       << " :: " << z << endl;
#define debug4(x, y, z, w)                                                     \
  cerr << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z         \
       << " :: " << z << "\t" << #w << " :: " << w << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define SIZE 5000 + 1
const ll MAX = 1e9;
const ll mod = 1e9;

ll expo(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = (ans * x) % mod;
    }
    x = (x * x) % mod;
    n >>= 1;
  }
  return ans;
}

vl adj[200001];
void solve() {
  ll n, i;
  cin >> n;
  vl a(n);
  ll sum = 0;
  fs(i, 2, n + 1) {
    cin >> a[i];
    adj[a[i]].pb(i);
  }
  fs(i, 1, n + 1) { cout << adj[i].size() << endl; }
}

int main() {
  boost;
  ll t = 1;
  // cin>>t;
  while (t--) {

    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
// #define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define maxe max_element
#define mine min_element
#define fn(i, x) for (i = 0; i < x; i++)
#define fs(i, s, x) for (i = s; i < x; i++)
#define fr(i, x) for (i = x; i >= 0; i--)
#define fit(itr, s) for (itr = s.begin(); itr != s.end(); itr++)
#define W while
#define pp pair<ll, ll>
#define ppi pair<ll, ll>
#define vl vector<ll>
#define vll vector<pp>
#define vi vector<int>
#define vii vector<ppi>
#define debug(x) cerr << #x << " :: " << x << endl;
#define debug2(x, y)                                                           \
  cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define debug3(x, y, z)                                                        \
  cerr << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z         \
       << " :: " << z << endl;
#define debug4(x, y, z, w)                                                     \
  cerr << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z         \
       << " :: " << z << "\t" << #w << " :: " << w << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define SIZE 5000 + 1
const ll MAX = 1e9;
const ll mod = 1e9;

ll expo(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = (ans * x) % mod;
    }
    x = (x * x) % mod;
    n >>= 1;
  }
  return ans;
}

vl adj[200001];
void solve() {
  ll n, i;
  cin >> n;
  vl a(n);
  ll sum = 0;
  fs(i, 1, n) {
    cin >> a[i];
    adj[a[i]].pb(i);
  }
  fs(i, 1, n + 1) { cout << adj[i].size() << endl; }
}

int main() {
  boost;
  ll t = 1;
  // cin>>t;
  while (t--) {

    solve();
  }
}