Problem p02707 (C++)

Buggy submission (status: Runtime Error):
// nani?
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (int i = a; i < b; i++)
#define sor(a) sort(a.begin(), a.end())
#define rsor(a) sort(a.rbegin(), a.rend())
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
// #define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const int inf = 1e7;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
// ac cmtr;
const int MAX_N = 1e5 + 5;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
//---------------------------

vector<ll> adj[MAX_N];

int main() {
  fastio;
  ll n;
  cin >> n;
  f(i, 0, n - 1) {
    ll num;
    cin >> num;
    adj[num].pb(i + 2);
  }
  f(i, 1, n + 1) { cout << adj[i].size() << endl; }
}

Fixed submission:
// nani?
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (int i = a; i < b; i++)
#define sor(a) sort(a.begin(), a.end())
#define rsor(a) sort(a.rbegin(), a.rend())
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
// #define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const int inf = 1e7;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
// ac cmtr;
const int MAX_N = 2e5 + 5;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
//---------------------------

vector<ll> adj[MAX_N];

int main() {
  fastio;
  ll n;
  cin >> n;
  f(i, 0, n - 1) {
    ll num;
    cin >> num;
    adj[num].pb(i + 2);
  }
  f(i, 1, n + 1) { cout << adj[i].size() << endl; }
}