output_description: Print 1+K lines, where K is the number of strongly connected components. Print
  K on the first line. Print the information of each strongly connected
  component in next K lines in the following format, where l is the number of
  vertices in the strongly connected component and v_i is the index of the
  vertex in it.
  
      
      
      l v_0 v_1 ... v_{l-1}
      
  
  Here, for each edge (a_i, b_i), b_i should not appear in **earlier** line than
  a_i.
  
  If there are multiple correct output, print any of them.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      a_0 b_0
      a_1 b_1
      :
      a_{M - 1} b_{M - 1}
attempt: import sys
  
  
  def SCC(G):
      D = []
      U = [1] * len(G)
      Z = []
      for x in range(len(G)):
          if U[x]:
              U[x] = 0
              Z.append((x, 1))
              for i in range(len(G[x])):
                  if U[G[x][i]]:
                      Z.append((G[x][i], 0))
                      U[G[x][i]] = 0
              while len(Z):
                  if Z[-1][1]:
                      D.append(Z[-1][0])
                      del Z[-1]
                  else:
                      x = Z[-1][0]
                      del Z[-1]
                      Z.append((x, 1))
                      for i in range(len(G[x])):
                          if U[G[x][i]]:
                              Z.append((G[x][i], 0))
                              U[G[x][i]] = 0
      GR = [[] for i in range(len(G))]
      for i in range(N):
          for j in range(len(G[i])):
              GR[G[i][j]].append(i)
      R = []
      U = [1] * len(G)
      for x in range(len(G) - 1, -1, -1):
          x = D[x]
          if U[x]:
              R.append([x])
              U[x] = 0
              for i in range(len(GR[x])):
                  if U[GR[x][i]]:
                      Z.append(GR[x][i])
                      U[GR[x][i]] = 0
              while len(Z):
                  x = Z[-1]
                  del Z[-1]
                  R[-1].append(x)
                  for i in range(len(GR[x])):
                      if U[GR[x][i]]:
                          Z.append(GR[x][i])
                          U[GR[x][i]] = 0
      return R
  
  
  S = sys.stdin.readlines()
  N, M = map(int, S[0].split())
  G = [[] for i in range(N)]
  a, b = 0, 0
  for i in range(M):
      a, b = map(int, S[i + 1].split())
      G[a].append(b)
  P = SCC(G)
  print(len(P))
  for i in range(len(P)):
      print(*([len(P[i])] + P[i]))
  
problem_description: Statement
  
  You are given a directed graph with N vertices and M edges, not necessarily
  simple. The i-th edge is oriented from the vertex a_i to the vertex b_i.
  Divide this graph into strongly connected components and print them in their
  topological order.
samples: [{"input": "6 7\n    1 4\n    5 2\n    3 0\n    5 5\n    4 1\n    0 3\n    4 2", "output": "4\n    1 5\n    2 4 1\n    1 2\n    2 3 0"}]