Problem p02707 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define cl(x) x.clear()
#define all(x) x.begin(), x.end()
#define r(x) scanf("%d", &x)
#define rr(x, y) scanf("%d%d", &x, &y)
#define rst(s) scanf("%s", s)
#define rl(x) scanf("%lld", &x)
#define rrl(x, y) scanf("%lld%lld", &x, &y)
#define w(x) printf("%d", x)
#define ww(x, y) printf("%d %d", x, y)
#define wl(x) printf("%lld", x)
#define wwl(x, y) printf("%lld %lld", x, y)
#define sp() printf(" ")
#define en() puts("")
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define mem0(x) memset(x, 0, sizeof(x))
#define mem_1(x) memset(x, -1, sizeof(x))
#define mem_inf(x) memset(x, inf, sizeof(x))
#define mem__inf(x) memset(x, -inf, sizeof(x))
#define p_queue priority_queue
#define debug(x) cout << x << '\n'
#define ddebug(x, y) cout << x << ' ' << y << '\n'
using namespace std;
// mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count())
// ;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = 30;
const ll mod = 1e9 + 7;
int n, in[maxn];
int main() {
  r(n);
  mem0(in);
  rep(i, 1, n - 1) {
    int x;
    r(x);
    in[x]++;
  }
  rep(i, 1, n) w(in[i]), en();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define cl(x) x.clear()
#define all(x) x.begin(), x.end()
#define r(x) scanf("%d", &x)
#define rr(x, y) scanf("%d%d", &x, &y)
#define rst(s) scanf("%s", s)
#define rl(x) scanf("%lld", &x)
#define rrl(x, y) scanf("%lld%lld", &x, &y)
#define w(x) printf("%d", x)
#define ww(x, y) printf("%d %d", x, y)
#define wl(x) printf("%lld", x)
#define wwl(x, y) printf("%lld %lld", x, y)
#define sp() printf(" ")
#define en() puts("")
#define rep(i, x, n) for (int i = x; i <= n; i++)
#define per(i, n, x) for (int i = n; i >= x; i--)
#define mem0(x) memset(x, 0, sizeof(x))
#define mem_1(x) memset(x, -1, sizeof(x))
#define mem_inf(x) memset(x, inf, sizeof(x))
#define mem__inf(x) memset(x, -inf, sizeof(x))
#define p_queue priority_queue
#define debug(x) cout << x << '\n'
#define ddebug(x, y) cout << x << ' ' << y << '\n'
using namespace std;
// mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count())
// ;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 30;
const ll mod = 1e9 + 7;
int n, in[maxn];
int main() {
  r(n);
  mem0(in);
  rep(i, 1, n - 1) {
    int x;
    r(x);
    in[x]++;
  }
  rep(i, 1, n) w(in[i]), en();
  return 0;
}