Language: C++

import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    System.out.println("N="+N +" M="+M );

    Map<Integer,List<Integer>> map=new HashMap<>();
    for(int i=0;i<M;i++){
      int v = sc.nextInt();
      int nv = sc.nextInt();
      List l =null;
      if(!map.containsKey(v)){
        l=new ArrayList();
      }else{
        l = map.get(v);
      }
      l.add(nv);
      map.put(v,l);
    }

    int max = -1;
    for(Integer v : map.keySet()){
      int ret = dfs(v,map);
      max = ret>max?ret:max;
    }
    System.out.println(max);
  }

  static int dfs(int v, Map<Integer,List<Integer>> map){

    if(!map.containsKey(v)) return 0;

    List<Integer> l = map.get(v);

    int max = -1;
    for(int nv: l){
      int ret = dfs(nv,map);
      max = ret>max?ret:max;
    }

    return max +1;
  }


}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:9: error: expected ':' before 'static'
    3 |   public static void main(String[] args){
      |         ^~~~~~~
      |         :
a.cc:3:27: error: 'String' has not been declared
    3 |   public static void main(String[] args){
      |                           ^~~~~~
a.cc:3:36: error: expected ',' or '...' before 'args'
    3 |   public static void main(String[] args){
      |                                    ^~~~
a.cc:31:25: error: 'Map' has not been declared
   31 |   static int dfs(int v, Map<Integer,List<Integer>> map){
      |                         ^~~
a.cc:31:28: error: expected ',' or '...' before '<' token
   31 |   static int dfs(int v, Map<Integer,List<Integer>> map){
      |                            ^
a.cc:47:2: error: expected ';' after class definition
   47 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:4:5: error: 'Scanner' was not declared in this scope
    4 |     Scanner sc = new Scanner(System.in);
      |     ^~~~~~~
a.cc:5:13: error: 'sc' was not declared in this scope
    5 |     int N = sc.nextInt();
      |             ^~
a.cc:7:5: error: 'System' was not declared in this scope
    7 |     System.out.println("N="+N +" M="+M );
      |     ^~~~~~
a.cc:7:31: error: invalid operands of types 'const char*' and 'const char [4]' to binary 'operator+'
    7 |     System.out.println("N="+N +" M="+M );
      |                        ~~~~~~ ^~~~~~
      |                            |   |
      |                            |   const char [4]
      |                            const char*
a.cc:9:5: error: 'Map' was not declared in this scope
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |     ^~~
a.cc:9:9: error: 'Integer' was not declared in this scope
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |         ^~~~~~~
a.cc:9:17: error: 'List' was not declared in this scope
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |                 ^~~~
a.cc:9:32: error: 'map' was not declared in this scope
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |                                ^~~
a.cc:9:40: error: 'HashMap' does not name a type
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |                                        ^~~~~~~
a.cc:9:48: error: expected primary-expression before '>' token
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |                                                ^
a.cc:9:50: error: expected primary-expression before ')' token
    9 |     Map<Integer,List<Integer>> map=new HashMap<>();
      |                                                  ^
a.cc:13:12: error: expected ';' before 'l'
   13 |       List l =null;
      |            ^
a.cc:15:9: error: 'l' was not declared in this scope
   15 |         l=new ArrayList();
      |         ^
a.cc:15:15: error: expected type-specifier before 'ArrayList'
   15 |         l=new ArrayList();
      |               ^~~~~~~~~
a.cc:17:9: error: 'l' was not declared in this scope
   17 |         l = map.get(v);
      |         ^
a.cc:19:7: error: 'l' was not declared in this scope
   19 |       l.add(nv);
      |       ^
a.cc:24:17: error: expected ';' before 'v'
   24 |     for(Integer v : map.keySet()){
      |                 ^
a.cc:29:3: error: expected primary-expression before '}' token
   29 |   }
      |   ^
a.cc:29:3: error: expected ')' before '}' token
a.cc:24:8: note: to match this '('
   24 |     for(Integer v : map.keySet()){
      |        ^
a.cc:29:3: error: expected primary-expression before '}' token
   29 |   }
      |   ^
a.cc: In static member function 'static int Main::dfs(int, int)':
a.cc:33:9: error: 'map' was not declared in this scope
   33 |     if(!map.containsKey(v)) return 0;
      |         ^~~
a.cc:35:5: error: 'List' was not declared in this scope
   35 |     List<Integer> l = map.get(v);
      |     ^~~~
a.cc:35:10: error: 'Integer' was not declared in this scope
   35 |     List<Integer> l = map.get(v);
      |          ^~~~~~~
a.cc:35:19: error: 'l' was not declared in this scope
   35 |     List<Integer> l = map.get(v);
      |                   ^
a.cc:35:23: error: 'map' was not declared in this scope
   35 |     List<Integer> l = map.get(v);
      |                       ^~~