Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

//----------BHAVIK DIWANI(PICT_COMP)---------------
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define FOR(p, n) for (ll i = p; i < (ll)n; i++)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ull power(ull a, ull b) {
  a %= mod;
  ull res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res % mod;
}
ll modmul(ll x, ll y) { return (x * y) % mod; }
ll modadd(ll x, ll y) { return (x + y) % mod; }
ll modsub(ll x, ll y) { return (x - y + mod) % mod; }
ll fact[1000007] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i < 100007; i++)
    fact[i] = (fact[i - 1] * i) % mod;
}
ll ncr(ll n, ll r) {
  ll res = 1;
  res = fact[n];
  res = (res * (power(fact[r], mod - 2))) % mod;
  res = (res * (power(fact[n - r], mod - 2))) % mod;
  return res;
}
ll npr(ll n, ll r) {
  ll res = 1;
  res = fact[n];
  res = (res * (power(fact[n - r], mod - 2))) % mod;
  return res;
}
#define MAX 1000005
#define forci(p, q) for (int i = p; i < q; i++)
bool prime[MAX];
/*ull sieve()
{
        memset(prime,true,sizeof(prime));
        for(ull p=2;p*p<MAX;p++)
        {
                if(prime[p]==true){
                        for(ull i=2*p;i<MAX;i+=p)
                        {
                                prime[i]=false;
                        }
                }
        }
        prime[0]=0;
        prime[1]=0;
}*/
using namespace std;
signed main() {
  fastio;
  int n;
  cin >> n;
  vector<int> g;
  int x;
  int freq[n + 5] = {0};
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    freq[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << freq[i] << endl;
  }
}


Error: TLE

Fixed submission:

//----------BHAVIK DIWANI(PICT_COMP)---------------
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define FOR(p, n) for (ll i = p; i < (ll)n; i++)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ull power(ull a, ull b) {
  a %= mod;
  ull res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res % mod;
}
ll modmul(ll x, ll y) { return (x * y) % mod; }
ll modadd(ll x, ll y) { return (x + y) % mod; }
ll modsub(ll x, ll y) { return (x - y + mod) % mod; }
ll fact[1000007] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i < 100007; i++)
    fact[i] = (fact[i - 1] * i) % mod;
}
ll ncr(ll n, ll r) {
  ll res = 1;
  res = fact[n];
  res = (res * (power(fact[r], mod - 2))) % mod;
  res = (res * (power(fact[n - r], mod - 2))) % mod;
  return res;
}
ll npr(ll n, ll r) {
  ll res = 1;
  res = fact[n];
  res = (res * (power(fact[n - r], mod - 2))) % mod;
  return res;
}
#define MAX 1000005
#define forci(p, q) for (int i = p; i < q; i++)
bool prime[MAX];
/*ull sieve()
{
        memset(prime,true,sizeof(prime));
        for(ull p=2;p*p<MAX;p++)
        {
                if(prime[p]==true){
                        for(ull i=2*p;i<MAX;i+=p)
                        {
                                prime[i]=false;
                        }
                }
        }
        prime[0]=0;
        prime[1]=0;
}*/
using namespace std;
signed main() {
  fastio;
  int n;
  cin >> n;
  vector<int> g;
  int x;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    g.pb(x);
  }
  for (int i = 1; i <= n; i++) {
    cout << count(g.begin(), g.end(), i) << endl;
  }
}