Language: C++

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();

		int N = sc.nextInt();
		int M = sc.nextInt();
		long[][] dist = new long[N][3];
		for (int i = 0; i < dist.length; ++i) {
			for (int j = 0; j < dist[i].length; ++j) {
				dist[i][j] = Long.MAX_VALUE / 3;
			}
		}
		class State implements Comparable<State> {
			long dist;
			int v;

			public State(long dist, int v) {
				this.dist = dist;
				this.v = v;
			}

			public int compareTo(State o) {
				return Long.compare(dist, o.dist);
			};
		}

		ArrayList<Integer>[] g = new ArrayList[N];
		for (int i = 0; i < N; ++i)
			g[i] = new ArrayList<>();
		for (int i = 0; i < M; ++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			--u;
			--v;
			g[u].add(v);
		}
		int s = sc.nextInt();
		int t = sc.nextInt();
		--s;
		--t;
		dist[s][0] = 0;
		PriorityQueue<State> pq = new PriorityQueue<>();
		pq.add(new State(0, 0));
		while (!pq.isEmpty()) {
			State state = pq.poll();
			if (state.dist > dist[state.v][(int) (state.dist % 3)]) {
				continue;
			}
			for (int dst : g[state.v]) {
				if (dist[dst][(int) (state.dist % 3 + 1) % 3] > state.dist + 1) {
					dist[dst][(int) (state.dist % 3 + 1) % 3] = state.dist + 1;
					pq.add(new State(dist[dst][(int) (state.dist % 3 + 1) % 3], dst));
				}
			}
		}
		if(dist[t][0]==Long.MAX_VALUE/3) {
			System.out.println(-1);
		}else {
			System.out.println(dist[t][0]/3);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.IOException;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.InputStream;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.ArrayList;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.Arrays;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.NoSuchElementException;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.PriorityQueue;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:15: error: expected ':' before 'static'
    9 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:9:33: error: 'String' has not been declared
    9 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:9:42: error: expected ',' or '...' before 'args'
    9 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:74:17: error: 'Object' has not been declared
   74 |         void tr(Object... objects) {
      |                 ^~~~~~
a.cc:74:27: error: expansion pattern 'int' contains no parameter packs
   74 |         void tr(Object... objects) {
      |                           ^~~~~~~
a.cc:78:2: error: expected ';' after class definition
   78 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:10:27: error: expected ';' before '.' token
   10 |                 new Main().run();
      |                           ^
a.cc: In member function 'void Main::run()':
a.cc:14:17: error: 'Scanner' was not declared in this scope
   14 |                 Scanner sc = new Scanner();
      |                 ^~~~~~~
a.cc:16:25: error: 'sc' was not declared in this scope
   16 |                 int N = sc.nextInt();
      |                         ^~
a.cc:18:21: error: structured binding declaration cannot have type 'long int'
   18 |                 long[][] dist = new long[N][3];
      |                     ^~
a.cc:18:21: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:18:21: error: empty structured binding declaration
a.cc:18:23: error: expected initializer before '[' token
   18 |                 long[][] dist = new long[N][3];
      |                       ^
a.cc:19:37: error: 'dist' was not declared in this scope
   19 |                 for (int i = 0; i < dist.length; ++i) {
      |                                     ^~~~
a.cc:21:46: error: 'Long' was not declared in this scope; did you mean 'long'?
   21 |                                 dist[i][j] = Long.MAX_VALUE / 3;
      |                                              ^~~~
      |                                              long
a.cc:24:40: error: expected initializer before 'Comparable'
   24 |                 class State implements Comparable<State> {
      |                                        ^~~~~~~~~~
a.cc:38:17: error: 'ArrayList' was not declared in this scope
   38 |                 ArrayList<Integer>[] g = new ArrayList[N];
      |                 ^~~~~~~~~
a.cc:38:27: error: 'Integer' was not declared in this scope
   38 |                 ArrayList<Integer>[] g = new ArrayList[N];
      |                           ^~~~~~~
a.cc: In lambda function:
a.cc:38:38: error: expected '{' before 'g'
   38 |                 ArrayList<Integer>[] g = new ArrayList[N];
      |                                      ^
a.cc: In member function 'void Main::run()':
a.cc:40:25: error: 'g' was not declared in this scope
   40 |                         g[i] = new ArrayList<>();
      |                         ^
a.cc:40:36: error: 'ArrayList' does not name a type
   40 |                         g[i] = new ArrayList<>();
      |                                    ^~~~~~~~~
a.cc:40:46: error: expected primary-expression before '>' token
   40 |                         g[i] = new ArrayList<>();
      |                                              ^
a.cc:40:48: error: expected primary-expression before ')' token
   40 |                         g[i] = new ArrayList<>();
      |                                                ^
a.cc:46:25: error: 'g' was not declared in this scope
   46 |                         g[u].add(v);
      |                         ^
a.cc:52:17: error: 'dist' was not declared in this scope
   52 |                 dist[s][0] = 0;
      |                 ^~~~
a.cc:53:17: error: 'PriorityQueue' was not declared in this scope
   53 |                 PriorityQueue<State> pq = new PriorityQueue<>();
      |                 ^~~~~~~~~~~~~
a.cc:53:36: error: expected primary-expression before '>' token
   53 |                 PriorityQueue<State> pq = new PriorityQueue<>();
      |                                    ^
a.cc:53:38: error: 'pq' was not declared in this scope
   53 |                 PriorityQueue<State> pq = new PriorityQueue<>();
      |                                      ^~
a.cc:53:47: error: 'PriorityQueue' does not name a type
   53 |                 PriorityQueue<State> pq = new PriorityQueue<>();
      |                                               ^~~~~~~~~~~~~
a.cc:53:61: error: expected primary-expression before '>' token
   53 |                 PriorityQueue<State> pq = new PriorityQueue<>();
      |                                                             ^
a.cc:53:63: error: expected primary-expression before ')' token
   53 |                 PriorityQueue<State> pq = new PriorityQueue<>();
      |                                                               ^
a.cc:54:38: error: invalid use of incomplete type 'class Main::run()::State'
   54 |                 pq.add(new State(0, 0));
      |                                      ^
a.cc:24:23: note: forward declaration of 'class Main::run()::State'
   24 |                 class State implements Comparable<State> {
      |                       ^~~~~
a.cc:56:31: error: variable 'Main::run()::State state' has initializer but incomplete type
   56 |                         State state = pq.poll();
      |                               ^~~~~
a.cc:60:40: error: 'g' was not declared in this scope
   60 |                         for (int dst : g[state.v]) {
      |                                        ^
a.cc:63:104: error: invalid use of incomplete type 'class Main::run()::State'
   63 |                                         pq.add(new State(dist[dst][(int) (state.dist % 3 + 1) % 3], dst));
      |                                                                                                        ^
a.cc:24:23: note: forward declaration of 'class Main::run()::State'
   24 |                 class State implements Comparable<State> {
      |                       ^~~~~
a.cc:67:32: error: 'Long' was not declared in this scope; did you mean 'long'?
   67 |                 if(dist[t][0]==Long.MAX_VALUE/3) {
      |                                ^~~~
      |                                long
a.cc:68:25: error: 'System' was not declared in this scope
   68 |                         System.out.println(-1);
      |                         ^~~~~~
a.cc:70:25: error: 'System' was not declared in this scope
   70 |                         System.out.println(dist[t][0]/3);
      |                         ^~~~~~
a.cc: In member function 'void Main::tr(...)':
a.cc:75:17: error: 'System' was not declared in this scope
   75 |                 System.out.println(Arrays.deepToString(objects));
      |                 ^~~~~~
a.cc:75:36: error: 'Arrays' was not declared in this scope
   75 |                 System.out.println(Arrays.deepToString(objects));
      |                                    ^~~~~~
a.cc:75:56: error: 'objects' was not declared in this scope
   75 |                 System.out.println(Arrays.deepToString(objects));
      |                                                        ^~~~~~~
a.cc: At global scope:
a.cc:81:16: error: expected ':' before 'final'
   81 |         private final InputStream in = System.in;
      |                ^~~~~~
      |                :
a.cc:81:17: error: 'final' does not name a type
   81 |         private final InputStream in = System.in;
      |                 ^~~~~
a.cc:82:16: error: expected ':' before 'final'
   82 |         private final byte[] buffer = new byte[1024];
      |                ^~~~~~
      |                :
a.cc:82:17: error: 'final' does not name a type
   82 |         private final byte[] buffer = new byte[1024];
      |                 ^~~~~
a.cc:83:16: error: expected ':' before 'int'
   83 |         private int ptr = 0;
      |                ^~~~
      |                :
a.cc:84:16: error: expected ':' before 'int'
   84 |         private int buflen = 0;
      |                ^~~~
      |                :
a.cc:86:16: error: expected ':' before 'boolean'
   86 |         private boolean hasNextByte() {
      |                ^~~~~~~~
      |                :
a.cc:86:17: error: 'boolean' does not name a type; did you mean 'bool'?
   86 |         private boolean hasNextByte() {
      |                 ^~~~~~~
      |                 bool
a.cc:103:16: error: expected ':' before 'int'
  103 |         private int readByte() {
      |                ^~~~
      |                :
a.cc:110:16: error: expected ':' before 'static'
  110 |         private static boolean isPrintableChar(int c) {
      |                ^~~~~~~
      |                :
a.cc:110:24: error: 'boolean' does not name a type; did you mean 'bool'?
  110 |         private static boolean isPrintableChar(int c) {
      |                        ^~~~~~~
      |                        bool
a.cc:114:16: error: expected ':' before 'void'
  114 |         private void skipUnprintable() {