Language: C++

/*
* @Author: dnhirapara
* @Date: 2020-04-30 22:24
* @Name: dp_g
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cerr << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

void in_out_file(){
    #ifdef _DEBUG
        freopen("F:/Coding/CompetitiveProg/static/input.txt", "r", stdin);
        freopen("F:/Coding/CompetitiveProg/static/output.txt", "w", stdout);
        freopen("F:/Coding/CompetitiveProg/static/debug.txt", "w", stderr);
    #endif
}

ll dp[100005] = {0};
bool vis[100005] = {0};
// int dfs(int n, vector<ll> graph[],vector<bool> &visited,vector<ll> &dist){
//     visited[n] = true;
//     int cnt = 0;
//     for(auto i : graph[n]){
//             log(i)
//             if(dist[i]!=-1)return dist[i];
//             cnt  = max(dist[i],dist[n]+1);
//             ans = max(dist[i],ans);
//             dfs(i, graph, visited, dist);
//     }
//     return dist[n] = cnt;
// }

ll dfs(ll n, std::vector<ll> g[]){
    if(vis[n])return dp[n];
    vis[n] = true;
    ll best = 0;
    for(auto i:g[n]){
        best = max(best, dfs(i,g)+1);
    }
    return dp[n] = best;
}

//@time comp :
//@space comp :
int main(){
    // cin.ignore(); must be there when using getline(cin, s)
    #ifndef AUTO
        in_out_file();
    #endif
    ll n, m;
    ll x, y;
    cin>>n>>m;
    std::vector<ll> graph[n+1];
    std::vector<ll> vertax(n+1);
    for(ll i=1;i<=m;i++){
        cin>>x>>y;
        graph[x].push_back(y);
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        ans = max(ans, dfs(i, graph));
    }
    cout<<ans<<endl;
    // for(ll i=1;i<=n;i++){
    //     cout<<i<<" -> ";
    //     for(auto j: graph[i]){
    //         cout<<j<<" ";
    //     }
    //     cout<<"\n";
    // }
    // std::vector<bool> visited(n+1);
    // for(ll i=0;i<n+1;i++){
    //     visited[i] = false;
    //     vertax[i] = -1;
    // }
    // for(ll i=1;i<n+1;i++){
    //     dfs(i, graph, visited, vertax);
    // }
    // for(ll i=1;i<=n;i++){
    //     log(vertax[i])
    // }
    // cout<<ans<<endl;
    return 0;
}
/*
* @Author: dnhirapara
* @Date: 2020-04-30 22:24
* @Name: dp_g
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define log(x) cerr << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

void in_out_file(){
    #ifdef _DEBUG
        freopen("F:/Coding/CompetitiveProg/static/input.txt", "r", stdin);
        freopen("F:/Coding/CompetitiveProg/static/output.txt", "w", stdout);
        freopen("F:/Coding/CompetitiveProg/static/debug.txt", "w", stderr);
    #endif
}

ll dp[100005] = {0};
bool vis[100005] = {0};
// int dfs(int n, vector<ll> graph[],vector<bool> &visited,vector<ll> &dist){
//     visited[n] = true;
//     int cnt = 0;
//     for(auto i : graph[n]){
//             log(i)
//             if(dist[i]!=-1)return dist[i];
//             cnt  = max(dist[i],dist[n]+1);
//             ans = max(dist[i],ans);
//             dfs(i, graph, visited, dist);
//     }
//     return dist[n] = cnt;
// }

ll dfs(ll n, std::vector<ll> g[]){
    if(vis[n])return dp[n];
    vis[n] = true;
    ll best = 0;
    for(auto i:g[n]){
        best = max(best, dfs(i,g)+1);
    }
    return dp[n] = best;
}

//@time comp :
//@space comp :
int main(){
    // cin.ignore(); must be there when using getline(cin, s)
    #ifndef AUTO
        in_out_file();
    #endif
    ll n, m;
    ll x, y;
    cin>>n>>m;
    std::vector<ll> graph[n+1];
    std::vector<ll> vertax(n+1);
    for(ll i=1;i<=m;i++){
        cin>>x>>y;
        graph[x].push_back(y);
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        ans = max(ans, dfs(i, graph));
    }
    cout<<ans<<endl;
    // for(ll i=1;i<=n;i++){
    //     cout<<i<<" -> ";
    //     for(auto j: graph[i]){
    //         cout<<j<<" ";
    //     }
    //     cout<<"\n";
    // }
    // std::vector<bool> visited(n+1);
    // for(ll i=0;i<n+1;i++){
    //     visited[i] = false;
    //     vertax[i] = -1;
    // }
    // for(ll i=1;i<n+1;i++){
    //     dfs(i, graph, visited, vertax);
    // }
    // for(ll i=1;i<=n;i++){
    //     log(vertax[i])
    // }
    // cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc:108:6: error: redefinition of 'void in_out_file()'
  108 | void in_out_file(){
      |      ^~~~~~~~~~~
a.cc:17:6: note: 'void in_out_file()' previously defined here
   17 | void in_out_file(){
      |      ^~~~~~~~~~~
a.cc:116:4: error: redefinition of 'long long int dp [100005]'
  116 | ll dp[100005] = {0};
      |    ^~
a.cc:25:4: note: 'long long int dp [100005]' previously defined here
   25 | ll dp[100005] = {0};
      |    ^~
a.cc:117:6: error: redefinition of 'bool vis [100005]'
  117 | bool vis[100005] = {0};
      |      ^~~
a.cc:26:6: note: 'bool vis [100005]' previously defined here
   26 | bool vis[100005] = {0};
      |      ^~~
a.cc:131:4: error: redefinition of 'long long int dfs(long long int, std::vector<long long int>*)'
  131 | ll dfs(ll n, std::vector<ll> g[]){
      |    ^~~
a.cc:40:4: note: 'long long int dfs(long long int, std::vector<long long int>*)' previously defined here
   40 | ll dfs(ll n, std::vector<ll> g[]){
      |    ^~~
a.cc:143:5: error: redefinition of 'int main()'
  143 | int main(){
      |     ^~~~
a.cc:52:5: note: 'int main()' previously defined here
   52 | int main(){
      |     ^~~~