output_description: Print 1 if G has cycle(s), 0 otherwise.
input_description: A directed graph G is given in the following format:
  
      
      
      |V| |E|
      s0 t0
      s1 t1
      :
      s|E|-1 t|E|-1
      
  
  |V| is the number of nodes and |E| is the number of edges in the graph. The
  graph nodes are named with the numbers 0, 1,..., |V|-1 respectively.
  
  si and ti represent source and target nodes of i-th edge (directed).
attempt: # Cycle Detection for a Directed Graph
  [vertex, edge] = list(map(int, input("").split()))
  array = [[0 for j in range(vertex)] for i in range(vertex)]
  
  for i in range(edge):
      data = list(map(int, input("").split()))
      array[data[0]][data[1]] = 1
  
  visited = [0 for j in range(vertex)]
  result = 0
  
  
  def dfs(node, goal):
      for t in range(vertex):
          visited[node] = 1
          if array[node][t] != 0 and t == goal:
              global result
              result = 1
          if array[node][t] != 0 and visited[t] == 0:
              dfs(t, goal)
  
  
  for i in range(vertex):
      visited = [0 for j in range(vertex)]
      dfs(i, i)
      if result == 1:
          print(1)
          break
  
  if result == 0:
      print(0)
  
problem_description: Cycle Detection for a Directed Graph
  
    
  
  Find a cycle in a directed graph G(V, E).
samples: [{"input": "3 3\n    0 1\n    0 2\n    1 2", "output": "0"}, {"input": "3 3\n    0 1\n    1 2\n    2 0", "output": "1"}]