Problem p03166 (C++)

Buggy submission (status: Runtime Error):
// People only find me interesting because they can't tell whether I'm serious
// or not #include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll) a.size()
#define lt(a) (ll) a.length()
#define pll pair<ll, ll>
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define bac(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define umll unordered_map<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define teevra_gati                                                            \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define N 3005
#define PI 3.14159265359
#define inf LLONG_MAX
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
vl adj[N];
ll indeg[N], lev[N], ans = 0;
void topo(ll n) {
  queue<ll> q;
  f(i, 1, n + 1) if (indeg[i] == 0) q.push(i);
  while (!q.empty()) {
    ll f = q.front();
    q.pop();
    for (auto u : adj[f]) {
      if (indeg[u]) {
        indeg[u]--;
        lev[u] = max(lev[u], 1 + lev[f]);
        if (!indeg[u])
          q.push(u);
      }
    }
  }
}

void solve() {
  ll n, m;
  cin >> n >> m;
  f(i, 0, m) {
    ll x, y;
    cin >> x >> y;
    adj[x].pb(y);
    indeg[y]++;
  }
  topo(n);
  f(i, 1, n + 1) { ans = max(ans, lev[i]); }
  cout << ans;
}
signed main() {
  teevra_gati

  solve();

  return 0;
}

Fixed submission:
// People only find me interesting because they can't tell whether I'm serious
// or not #include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll) a.size()
#define lt(a) (ll) a.length()
#define pll pair<ll, ll>
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define bac(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define umll unordered_map<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define teevra_gati                                                            \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define N 100005
#define PI 3.14159265359
#define inf LLONG_MAX
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
vl adj[N];
ll indeg[N], lev[N], ans = 0;
void topo(ll n) {
  queue<ll> q;
  f(i, 1, n + 1) if (indeg[i] == 0) q.push(i);
  while (!q.empty()) {
    ll f = q.front();
    q.pop();
    for (auto u : adj[f]) {
      if (indeg[u]) {
        indeg[u]--;
        lev[u] = max(lev[u], 1 + lev[f]);
        if (!indeg[u])
          q.push(u);
      }
    }
  }
}

void solve() {
  ll n, m;
  cin >> n >> m;
  f(i, 0, m) {
    ll x, y;
    cin >> x >> y;
    adj[x].pb(y);
    indeg[y]++;
  }
  topo(n);
  f(i, 1, n + 1) { ans = max(ans, lev[i]); }
  cout << ans;
}
signed main() {
  teevra_gati

  solve();

  return 0;
}