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(){ List[] E = new List[N]; for(int i=0;i(); Func canGo = (a,b) =>{ for(int i=0;i<3;i++) if(a[i] > b[i]) return false; return true; }; int[] Indeg = new int[N]; for(int i=0;i Q = new Queue(); for(int i=0;i0){ var now = Q.Dequeue(); foreach(var nxt in E[now]){ Indeg[nxt]--; max[nxt] = Math.Max(max[nxt],max[now]+1); if(Indeg[nxt] == 0){ Q.Enqueue(nxt); } } } Console.WriteLine(max.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));} }