using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ int[] InDeg= new int[N]; List[] E = new List[N]; for(int i=0;i(); } for(int i=0;i Q = new Queue(); for(int i=0;i 0){ var now = Q.Dequeue(); foreach(var nxt in E[now]){ dp[nxt] = Math.Max(dp[nxt],dp[now]+1); InDeg[nxt]--; if(InDeg[nxt] == 0) Q.Enqueue(nxt); } } Console.WriteLine(dp.Max()); } int N; int[][] B; public Sol(){ N = ri(); B = new int[N][]; for(int i=0;iint.Parse(e));} static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));} static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));} }