Problem p03166 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mod 1000000007
#define check exit(0)
#define nl cout << endl;
#define inp 10
#define ordered_set                                                            \
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define deb(v)                                                                 \
  for (int i = 0; i < v.size(); i++) {                                         \
    cout << v[i];                                                              \
    (i == v.size() - 1) ? cout << "\n" : cout << " ";                          \
  }
#define jaldi                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

vector<int> g[100005];
vector<bool> visited(100005, false);
vector<int> start(inp, 0);

void dfs(int n) {
  if (visited[n])
    return;
  visited[n] = true;
  for (int c : g[n]) {
    dfs(c);
    start[n] = max(start[n], 1 + start[c]);
  }
}

int main() {
  jaldi

      int n,
      m;
  cin >> n >> m;

  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
  }

  for (int i = 1; i <= n; i++) {
    if (!visited[i])
      dfs(i);
  }

  for (int i = 1; i <= n; i++)
    visited[i] = false;

  // deb(start);
  //  for(int i=1;i<=n;i++)
  //  {
  //      if(!visited[i]) dfs(i);
  //  }

  // deb(start);

  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = max(ans, start[i]);
  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mod 1000000007
#define check exit(0)
#define nl cout << endl;
#define inp 200005
#define ordered_set                                                            \
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define deb(v)                                                                 \
  for (int i = 0; i < v.size(); i++) {                                         \
    cout << v[i];                                                              \
    (i == v.size() - 1) ? cout << "\n" : cout << " ";                          \
  }
#define jaldi                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

// Pick yourself up, 'cause...

vector<int> g[100005];
vector<bool> visited(100005, false);
vector<int> start(inp, 0);

void dfs(int n) {
  if (visited[n])
    return;
  visited[n] = true;
  for (int c : g[n]) {
    dfs(c);
    start[n] = max(start[n], 1 + start[c]);
  }
}

int main() {
  jaldi

      int n,
      m;
  cin >> n >> m;

  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
  }

  for (int i = 1; i <= n; i++) {
    if (!visited[i])
      dfs(i);
  }

  for (int i = 1; i <= n; i++)
    visited[i] = false;

  // deb(start);
  //  for(int i=1;i<=n;i++)
  //  {
  //      if(!visited[i]) dfs(i);
  //  }

  // deb(start);

  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = max(ans, start[i]);
  cout << ans;

  return 0;
}