stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#define el				'\n'

#define sz(v)			((int)((v).size()))

#define all(v)          ((v).begin()),((v).end())

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 1e5 + 9, M = 50 + 9, OO = (int) 1e9 + 1;

const long long MOD = 1e9 + 7;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(12);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	//freopen("output.txt", "w", stdout);

#endif

	cout << fixed << setprecision(0);

//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



int n, m, x, y, vis[N], ans;

vector<vector<int>> edges(N);



int DFS(int node) {

	if (vis[node] != -1)

		return vis[node];

	vis[node] = 0;

	for (auto child : edges[node]) {

		DFS(child);

		vis[node] = max(vis[node], vis[child] + 1);

	}

	return 0;

}



int main() {

//	INPUT();

	OUTPUT();

	clr(vis, -1);

	cin >> n >> m;

	for (int i = 0; i < m; ++i) {

		cin >> x >> y;

		edges[x].push_back(y);

	}

	for (int j = 1; j <= n; j++) {

		DFS(j);

	}

	for (int i = 1; i <= n; i++) {

		ans = max(ans, vis[i]);

	}

	cout << ans;



	return 0;



}


// Faster C++ solution for the same problem (measured speedup: 3.9018581399174717x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
// Author : Syed Mujtaba

// Seek knowledge from the Cradle to the Grave !!

// https://www.linkedin.com/in/syed-mujtaba-064a5016a 



#include <bits/stdc++.h>

using namespace std;

#define int     long long

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define mod ((int)(1e9 + 7))

vector < int > to[100005];

vector < int > from[100005];

vector < int > roots;

int dp[100005];

int cal(int i)

{

	if(dp[i] != -1)

		return dp[i];

	int dist = -1;

	for(int j = 0; j < to[i].size(); j++)

	{

		dist = max(dist, 1 + cal(to[i][j]));

	}

	return dp[i] = dist;

}

signed main()

{

	fast_io

	int n, m;

	int x, y;

	cin >> n >> m;

	for(int i = 0; i < m; i++)

	{	

		cin >> x >> y;

		to[y].push_back(x);

		from[x].push_back(y);

	}

	for(int i = 1; i <= n; i++)

		dp[i] = -1;

	for(int i = 1; i <= n; i++)

	{

		if(to[i].size() == 0)

		{

			roots.push_back(i);

			dp[i] = 0;

		}

	}

	for(int i = 1; i <= n; i++)

	{

		if(dp[i] == -1)

			dp[i] = cal(i);

	}

	int ans = -1;

	for(int i = 1; i <= n; i++)

	{

		ans = max(ans, dp[i]);

	}

	cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 6.287803536438522x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

vector<int>adj[100005];

int dp[100005];

bool vis[100005];

void dfs(int u)

{

    vis[u]=true;

    for(auto v:adj[u])

    {

        if(vis[v]==false)

            dfs(v);

        dp[u]=max(dp[u],dp[v]+1);

    }





}

int main()

{

    int n,m;

    cin>>n>>m;

    for(int i=1; i<=m; i++)

    {

        int u,v;

        cin>>u>>v;

        adj[u].push_back(v);

    }

    for(int i=1; i<=n; i++)

    {

        if(vis[i]==false)

            dfs(i);

    }

    int ans=0;

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

    cout<<ans<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 3.4581389244232486x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ull unsigned long long

#define PII pair<int,int>

#define PSI pair<string,int>

#define PIII pair< int, pair<int,int> >

const int MaxN = 1e5+5;

vector<int> g[MaxN];

int dp[MaxN];

int N;



int dfs(int node, int pr){



    auto &ret = dp[node];

    if(ret!=-1) return ret;

    ret = 0;

    for(auto i: g[node]){

        if(i==pr) continue;

        ret = max( ret, dfs(i,node)+1 );

    }



    return ret;

}



void read(){



    int i,edge;

    memset(dp,-1,sizeof dp);

    cin>>N>>edge;

    for(i=0; i<edge; i++){

        int u,v;

        cin>>u>>v;

        g[u].push_back(v);

    }

}



void solve(){



    read();

    int res = 0;

    for(int i=1; i<=N; i++){

        res = max( res, dfs(i,0) );

    }



    cout<< res << "\n";

}



int main(){



    //freopen("input.txt","r",stdin);

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    solve();

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.8759462114050267x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

int dp[maxn],deg[maxn];

vector<int> G[maxn];



int get(int u)

{

	if(dp[u]) return dp[u];

	for(auto it:G[u])

	dp[u]=max(dp[u],get(it)+1);

	return dp[u];

}



int main()

{

	int n,m,x,y;

	cin>>n>>m;

	

	while(m--) 

	{

		 cin>>x>>y;

		 deg[y]++;

		 G[x].push_back(y);

	}

	

	int ans=0;

	for(int i=1;i<=n;i++)

	if(deg[i]==0) ans=max(ans,get(i));

	

	cout<<ans<<endl;

	

	return 0;

 } 

// Faster C++ solution for the same problem (measured speedup: 3.4581344946477492x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;

typedef vector<int> vi; 

typedef long long ll;

#define pb push_back

#define fi first

#define se second

#define rep(i,a,b) for(int i=(a);i<=(int)(b);i++)

#define per(i,a,b) for(int i=(a);i>=(int)(b);i--)

const int mod = 1e9+7;

const int maxn = 1e5+10;

const int inf = 0x3f3f3f3f;

vi g[maxn];

queue<int> q;

int dp[maxn],du[maxn];

int main()

{

    ios::sync_with_stdio(false);cin.tie(nullptr);

    //freopen("in1.txt","r",stdin);

    int n,m;

    cin>>n>>m;

    rep(i,1,m) {

        int u,v;

        cin>>u>>v;

        g[u].pb(v);

        du[v]++;

    }

    rep(i,1,n) {

        if(du[i]==0) q.push(i);

    }

    while(!q.empty()) {

        int now=q.front();q.pop();

        for(int x:g[now]) {

            du[x]--;

            if(du[x]==0) q.push(x);

            dp[x]=max(dp[x],dp[now]+1);

        }

    }

    int Max=0;

    rep(i,1,n) {

        Max=max(Max,dp[i]);

    }

    cout<<Max<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.4870550898996706x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include <iostream>

#include <stdio.h>

#include <vector>

#include <cstring>

using namespace std;

int n,m;

const int N=1e5+9;

int memo[N];

vector <vector<int> >graph;

int dp(int i)

{

    if(graph[i].empty())

        return 0;

    int &ret=memo[i];

    if(~ret)

        return ret;



    for(int u:graph[i])

    {

        ret=max(ret,dp(u)+1);

    }

    return ret;

}

int main()

{

    memset(memo,-1,sizeof memo);



    scanf("%d %d",&n,&m);

    graph.resize(n+1);

    while(m--)

    {

        int u,v;

        scanf("%d %d",&u,&v);

        graph[u].push_back(v);

    }

    int ans=0;

    for(int i=1;i<=n;++i)

        ans=max(dp(i),ans);

    printf("%d\n",ans);



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.363501260154841x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long int

#define Mx 100005

using namespace std;

ll n,m;

vector<ll>graph[Mx];

bool vis[Mx];

ll dp[Mx];

void input()

{



    cin>>n>>m;

    for(int i=0; i<m; i++)

    {

        ll x,y;

        cin>>x>>y;

        graph[x].push_back(y);

    }





}

void DFS(ll src)

{

    ll c=1;

    vis[src]=true;

    for(ll i=0; i<graph[src].size(); i++)

    {

        if(!vis[graph[src][i]])

        {

            DFS(graph[src][i]);

        }

        dp[src]=max(dp[src],c+dp[graph[src][i]]);

    }

}





int main()

{

    input();

    for(int i=1; i<=n; i++)

    {

        if(!vis[i])

        {

            DFS(i);

        }

    }

    ll mx=0;

    for(int i=0;i<=Mx;i++) {

        mx=max(mx,dp[i]);

    }

    cout<<mx<<endl;





}


// Faster C++ solution for the same problem (measured speedup: 3.7904698610407013x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)

#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)

#define pb push_back

#define all(v) ((v.begin()),(v.end()))

#define memset(c, value) memset(c, (int)value, sizeof(c))

using namespace std;

typedef long long ll;

const ll oo = 1e18;

const ll MOD =1e9+7;

const double pi = acos(-1);

void fast(){

    ios_base :: sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int n, m;

bool valid (int r,int c){

    return (r < n && r >= 0 && c >= 0 && c < m);

}



int row[] = {0 , 1 , 0, -1};

int column[] = {1 , 0, -1, 0};



vector<int> adj[100001];

int path[100001];

int vis[100001];



int dp(int u){

    if(path[u]!=-1)

        return path[u];



    vis[u] = true;



    int sz = adj[u].size();



    path[u] = 0;

    f(j, 0, sz){

        if(!vis[adj[u][j]])

            path[u] = max( path[u], 1 + dp(adj[u][j]));

    }

    vis[u] = false;



    return path[u];

}





int main()

{

    fast();



    int u, v;

    cin>>n>>m;

    f(i, 0, m){

        cin>>u>>v;

        adj[u].push_back(v);

    }

    int maxi = 0;

    memset(vis, 0);

    memset(path, -1);



    f(i, 1, n+1){



        maxi = max(maxi, dp(i));

    }



    cout<<maxi<<'\n';

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.306740147898034x):
#include<bits/stdc++.h>

#define ll          long long int

#define ld          long double

#define pb          push_back

#define mp          make_pair

#define ff          first

#define se          second

#define scan(n)     scanf("%lld", &n);

#define print(n)    printf("%lld\n", n);

#define fd(n)       fixed<<setprecision(n)

#define MAX         1000000000000000000

#define MAXN        100005

#define LOG         19

#define mod         1000000007

using namespace std;





int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n,m,i,x,y,mx=0;

    cin>>n>>m;

    vector<ll> vi[n+1];

    ll deg[n+1];

    queue<ll> qe;

    vector<ll> vi1;

    memset(deg,0,sizeof(deg));

    for(i=1;i<=m;i++){

        cin>>x>>y;

        vi[x].pb(y);

        deg[y]++;

    }

    for(i=1;i<=n;i++){

        if(deg[i]==0){

            qe.push(i);

            vi1.pb(i);

        }

    }

    while(!qe.empty()){

        ll node=qe.front();

        qe.pop();

        for(auto x:vi[node]){

            deg[x]--;

            if(deg[x]==0){

                vi1.pb(x);

                qe.push(x);

            }

        }

    }

    ll dp[n+1];

    memset(dp,0,sizeof(dp));

    for(auto node:vi1){

        for(auto x:vi[node]){

            dp[x]=max(dp[x],dp[node]+1);

        }

    }

    for(i=1;i<=n;i++){

        mx=max(mx,dp[i]);

    }

    cout<<mx;

}