Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int N,M;
bool visited[100100];
int dp[100100]={0};
vector<int> G[100100],v;

void dfs(int s){
  visited[s]=1;
  for(int i=0;i<G[s].size();i++){
    if(!visited[G[s][i]]){
      dfs(G[s][i]);
    }
  }
  v.push_back(s);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  int x,y;
  for(int i=0;i<M;i++){
    cin >> x >>y;
    x--;
    y--;
    G[x].push_back(y);
  }

  for(int i=0;i<N;i++){
    if(!visited[i]){
      dfs(i);
    }
  }
  reverse(v.begin(),v.end());

 int ans=0;
 for(int i=0;i<N;i++){
   for(int j=0;j<G[v[i]].size();j++){
     dp[G[v[i]][j]]=max(dp[G[v[i]][j]],dp[v[i]]+1);
   }
   ans=max(ans,dp[v[i]]);
 }
 cout << ans << endl;
 return 0;
}
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<int, int> P;
priority_queue<P, vector<P>, greater<P>> pque;

int N,M;
bool visited[100100];
int dp[100100]={0};
vector<int> G[100100],v;

void dfs(int s){
 visited[s]=1;
 for(int i=0;i<G[s].size();i++){
   if(!visited[G[s][i]]){
     dfs(G[s][i]);
   }
 }
 v.push_back(s);
}

int main(){
 ios::sync_with_stdio(false);
 cin.tie(NULL);
 cin >> N >> M;
 int x,y;
 for(int i=0;i<M;i++){
   cin >> x >> y;
   x--;
   y--;
   G[x].push_back(y);
 }

 for(int i=0;i<N;i++){
   if(!visited[i]){
     dfs(i);
   }
 }
 reverse(v.begin(),v.end());

 int ans=0;
 for(int i=0;i<N;i++){
   for(int j=0;j<G[v[i]].size();j++){
     dp[G[v[i]][j]]=max(dp[G[v[i]][j]],dp[v[i]]+1);
   }
   ans=max(ans,dp[v[i]]);
 }
 cout << ans << endl;
 return 0;
}

Compiler output:
a.cc:116:16: error: redefinition of 'std::map<int, int> mpa'
  116 | map <int ,int> mpa,mpb;
      |                ^~~
a.cc:34:16: note: 'std::map<int, int> mpa' previously declared here
   34 | map <int ,int> mpa,mpb;
      |                ^~~
a.cc:116:20: error: redefinition of 'std::map<int, int> mpb'
  116 | map <int ,int> mpa,mpb;
      |                    ^~~
a.cc:34:20: note: 'std::map<int, int> mpb' previously declared here
   34 | map <int ,int> mpa,mpb;
      |                    ^~~
a.cc:117:24: error: conflicting declaration 'typedef struct std::pair<int, int> P'
  117 | typedef pair<int, int> P;
      |                        ^
a.cc:35:22: note: previous declaration as 'typedef struct std::pair<long long int, long long int> P'
   35 | typedef pair<ll, ll> P;
      |                      ^
a.cc:118:42: error: redefinition of 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > > pque'
  118 | priority_queue<P, vector<P>, greater<P>> pque;
      |                                          ^~~~
a.cc:36:42: note: 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > > pque' previously declared here
   36 | priority_queue<P, vector<P>, greater<P>> pque;
      |                                          ^~~~
a.cc:120:5: error: redefinition of 'int N'
  120 | int N,M;
      |     ^
a.cc:38:5: note: 'int N' previously declared here
   38 | int N,M;
      |     ^
a.cc:120:7: error: redefinition of 'int M'
  120 | int N,M;
      |       ^
a.cc:38:7: note: 'int M' previously declared here
   38 | int N,M;
      |       ^
a.cc:121:6: error: redefinition of 'bool visited [100100]'
  121 | bool visited[100100];
      |      ^~~~~~~
a.cc:39:6: note: 'bool visited [100100]' previously declared here
   39 | bool visited[100100];
      |      ^~~~~~~
a.cc:122:5: error: redefinition of 'int dp [100100]'
  122 | int dp[100100]={0};
      |     ^~
a.cc:40:5: note: 'int dp [100100]' previously defined here
   40 | int dp[100100]={0};
      |     ^~
a.cc:123:13: error: redefinition of 'std::vector<int> G [100100]'
  123 | vector<int> G[100100],v;
      |             ^
a.cc:41:13: note: 'std::vector<int> G [100100]' previously declared here
   41 | vector<int> G[100100],v;
      |             ^
a.cc:123:23: error: redefinition of 'std::vector<int> v'
  123 | vector<int> G[100100],v;
      |                       ^
a.cc:41:23: note: 'std::vector<int> v' previously declared here
   41 | vector<int> G[100100],v;
      |                       ^
a.cc:125:6: error: redefinition of 'void dfs(int)'
  125 | void dfs(int s){
      |      ^~~
a.cc:43:6: note: 'void dfs(int)' previously defined here
   43 | void dfs(int s){
      |      ^~~
a.cc:135:5: error: redefinition of 'int main()'
  135 | int main(){
      |     ^~~~
a.cc:53:5: note: 'int main()' previously defined here
   53 | int main(){
      |     ^~~~