For this Question: Given a directed graph of N vertices, Print 1 if you can perform a topological sort on the given graph. Otherwise, print 0.

There are no self-loops or multiple edges.The first line contains two integers N and E, denoting the number of nodes and number of edges in the graph respectively. Next E lines contain two integers u and v, denoting an edge from u to v

Constraints
1 <= N, E <= 1000
0 <= u,  v <= N-1
u != vPrint 1 if topological sort can be done correctly. Otherwise, print 0.Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2

Sample Output 1:
0

Sample Input 2:
4 3
0 1
1 2
2 3

Sample Output 2:
1
, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
    static ArrayList<ArrayList<Integer>> adj;


    static void graph(int v){
        adj =new ArrayList<>();
        for(int i=0;i<=v;i++) adj.add(new ArrayList<Integer>());
    }


    static void addedge(int u, int v){
        adj.get(u).add(v);
    }

    static boolean dfs(int i, boolean [] vis, int parent[]){
        vis[i] = true; parent[i] = 1;
        for(Integer it: adj.get(i)){
            if(vis[it]==false) {
                if(dfs(it, vis, parent)==true) return true;
            }
            else if(parent[it]==1) return true;
        }
        parent[i] = 0;
        return false;
    }

    static boolean helper(int n){
        boolean vis[] = new boolean [n+1];
        int parent[] = new int[n+1];


            int i=1;
            if(vis[i]==false){

                if(dfs(i, vis, parent)) return true;
            }


        return false;
    }

    public static void main (String[] args) throws Exception{
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String t[] = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        graph(n);
        int e = Integer.parseInt(t[1]);
        for(int i=0;i<e;i++) {
            String num[] = br.readLine().split(" ");
            int u = Integer.parseInt(num[0]);
            int v = Integer.parseInt(num[1]);
            addedge(u, v);
        }
        if(helper(n)) System.out.println("0");
        else System.out.println("1");
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?