Language: Java

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

public class Main implements Runnable {
  public static void main(String[] args) {
    new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
  }
  public void run() {
    static int V;
    static List<List<Integer>> G;
    static List<List<Integer>> rG;
    static List<Integer> vs;
    static boolean[] used;
    static int[] cmp;
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int e = Integer.parseInt(sc.next());
    V = n;
    G = new ArrayList<List<Integer>>(n);
    rG = new ArrayList<List<Integer>>(n);
    vs = new ArrayList<Integer>();
    used = new boolean[n];
    cmp = new int[n];

    for(int i = 0; i < n; i++) {
      G.add(new ArrayList<Integer>());
      rG.add(new ArrayList<Integer>());
    }

    for(int i = 0; i < e; i++) {
      int from = Integer.parseInt(sc.next());
      int to = Integer.parseInt(sc.next());
      G.get(from).add(to);
      rG.get(to).add(from);
    }

    for(int i = 0; i < V; i++) {
      used[i] = false;
    }
    vs.clear();

    for(int i = 0; i < V; i++) {
      if(!used[i]) dfs(i);
    }

    for(int i = 0; i < V; i++) {
      used[i] = false;
    }

    int k = 0;  
    for(int i = vs.size() - 1; i >= 0; i--) {
      if(!used[vs.get(i)]) rdfs(vs.get(i), k++);
    }

    int q = Integer.parseInt(sc.next());
    for(int i = 0; i < q; i++) {
      int s = Integer.parseInt(sc.next());
      int t = Integer.parseInt(sc.next());
      if(cmp[s] == cmp[t]) {
        System.out.println(1);
      }
      else{
        System.out.println(0);
      }
    }
  }

  static void dfs(int v) {
    used[v] = true; 
    for(int i = 0; i < G.get(v).size(); i++) {
      if(!used[G.get(v).get(i)]) dfs(G.get(v).get(i));
    }
    vs.add(v);
  }
  
  static void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for(int i = 0; i < rG.get(v).size(); i++) {
      if(!used[rG.get(v).get(i)]) rdfs(rG.get(v).get(i), k);
    }
  }
}

Compiler output:
Main.java:11: error: illegal start of expression
    static int V;
    ^
Main.java:20: error: <identifier> expected
    V = n;
     ^
Main.java:21: error: <identifier> expected
    G = new ArrayList<List<Integer>>(n);
     ^
Main.java:22: error: <identifier> expected
    rG = new ArrayList<List<Integer>>(n);
      ^
Main.java:23: error: <identifier> expected
    vs = new ArrayList<Integer>();
      ^
Main.java:24: error: <identifier> expected
    used = new boolean[n];
        ^
Main.java:25: error: <identifier> expected
    cmp = new int[n];
       ^
Main.java:27: error: illegal start of type
    for(int i = 0; i < n; i++) {
    ^
Main.java:27: error: > or ',' expected
    for(int i = 0; i < n; i++) {
                        ^
Main.java:27: error: <identifier> expected
    for(int i = 0; i < n; i++) {
                           ^
Main.java:32: error: illegal start of type
    for(int i = 0; i < e; i++) {
    ^
Main.java:32: error: > or ',' expected
    for(int i = 0; i < e; i++) {
                        ^
Main.java:32: error: <identifier> expected
    for(int i = 0; i < e; i++) {
                           ^
Main.java:39: error: illegal start of type
    for(int i = 0; i < V; i++) {
    ^
Main.java:39: error: > or ',' expected
    for(int i = 0; i < V; i++) {
                        ^
Main.java:39: error: <identifier> expected
    for(int i = 0; i < V; i++) {
                           ^
Main.java:42: error: <identifier> expected
    vs.clear();
            ^
Main.java:44: error: illegal start of type
    for(int i = 0; i < V; i++) {
    ^
Main.java:44: error: > or ',' expected
    for(int i = 0; i < V; i++) {
                        ^
Main.java:44: error: <identifier> expected
    for(int i = 0; i < V; i++) {
                           ^
Main.java:48: error: illegal start of type
    for(int i = 0; i < V; i++) {
    ^
Main.java:48: error: > or ',' expected
    for(int i = 0; i < V; i++) {
                        ^
Main.java:48: error: <identifier> expected
    for(int i = 0; i < V; i++) {
                           ^
Main.java:53: error: illegal start of type
    for(int i = vs.size() - 1; i >= 0; i--) {
    ^
Main.java:53: error: <identifier> expected
    for(int i = vs.size() - 1; i >= 0; i--) {
                                ^
Main.java:53: error: <identifier> expected
    for(int i = vs.size() - 1; i >= 0; i--) {
                                        ^
Main.java:58: error: illegal start of type
    for(int i = 0; i < q; i++) {
    ^
Main.java:58: error: > or ',' expected
    for(int i = 0; i < q; i++) {
                        ^
Main.java:58: error: <identifier> expected
    for(int i = 0; i < q; i++) {
                           ^
Main.java:70: error: unnamed classes are a preview feature and are disabled by default.
  static void dfs(int v) {
         ^
  (use --enable-preview to enable unnamed classes)
Main.java:85: error: class, interface, enum, or record expected
}
^
31 errors