Language: Java

import java.util.*;
import java.io.*;

public class Main {
  
  public static void main(String[] abc) {
     Main answer = new Main();
     long solution = answer.solve();
     System.out.println(solution);
  }
  
  private int[] dp;
  
  private long solve() {
     Scanner sc = new Scanner();     
     int N = sc.nextInt();
     int M = sc.nextInt();
     Map<Integer, List<Integer>> graph = new HashMap<>();
     for(int i=0;i<M;i++) {
        int u = sc.nextInt();
        int v = sc.nextInt();
        List<Integer> children = graph.getOrDefault(u, new ArrayList<>());        
        children.add(v);
        graph.put(u, children);
     }
     int bestLen =0;
     dp = new int[N];
     Arrays.fill(dp, -1);
     for(int i=1;i<=N;i++) {
       bestLen = Math.max(bestLen, getBestLen(i, graph));
     }
     return bestLen;
  }
	  
  private int getBestLen(int u, Map<Integer, List<Integer>> graph) {
	 if (dp[u]!=-1) return dp[u];
     if (!graph.containsKey(u)){
        dp[u]=0;
        return dp[u];
     } else {
        int bestChildLen=0;
        for(int child: graph.get(u)){
         	 int currChildLen = getBestLen(child, graph);
             bestChildLen = Math.max(bestChildLen, currChildLen);
        }
		dp[u] = bestChildLen+1;
        return dp[u];
     }
  }
}


Compiler output:
Main.java:15: error: no suitable constructor found for Scanner(no arguments)
     Scanner sc = new Scanner();     
                  ^
    constructor Scanner.Scanner(Readable,Pattern) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Readable) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(InputStream) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(InputStream,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(InputStream,Charset) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File,Charset) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(File,CharsetDecoder) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Path) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Path,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(Path,Charset) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(ReadableByteChannel) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(ReadableByteChannel,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor Scanner.Scanner(ReadableByteChannel,Charset) is not applicable
      (actual and formal argument lists differ in length)
1 error