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.First line consists of two space separated integers denoting N and M.
Each of the following M lines consists of two space separated integers X and Y denoting there is an from X directed towards Y.

1 <= N, M <= 2*10^5
1 <= X, Y <= NPrint 1 if topological sort can be done correctly. Otherwise print 0 .Input
5 6
1 2
1 3
2 3
2 4
3 4
3 5

Output
1
, I have written this Solution Code: from collections import defaultdict
 

class Graph:
    def __init__(self, vertices):
        self.graph = defaultdict(list)
        self.V = vertices 
 
  
    def addEdge(self, u, v):
        self.graph[u].append(v)
 
 
 
    def topologicalSort(self):
         
       
        in_degree = [0]*(self.V)
         
       
        for i in self.graph:
            for j in self.graph[i]:
                in_degree[j] += 1
 
       
        queue = []
        for i in range(self.V):
            if in_degree[i] == 0:
                queue.append(i)
 
        
        cnt = 0
 
      
        top_order = []
 
        
        while queue:
 
            
            u = queue.pop(0)
            top_order.append(u)
 
           
            for i in self.graph[u]:
                in_degree[i] -= 1
               
                if in_degree[i] == 0:
                    queue.append(i)
 
            cnt += 1
 
      
        if cnt != self.V:
            print ("0")
        else :
           
            print ("1")
V,E=map(int,input().split())
g=Graph(V)
for _ in range(E):
    u,v=map(int,input().split())
    g.addEdge(u-1,v-1)
g.topologicalSort(), In this Programming Language: Python, Now tell me if this Code is compilable or not?