output_description: In the first line, print the maximized flow by reversing some roads. In the
  second line, print the number R of the reversed roads. In each of the
  following R lines, print the ID number (1-based) of a reversed road. You may
  not print the same ID number more than once.
  
  If there are multiple answers which would give us the same flow capacity, you
  can print any of them.
input_description: The first line of a data set contains two integers N (2 \leq N \leq 300) and M
  (0 \leq M \leq {\rm min} (1\,000,\ N(N-1)/2)). N is the number of crossings in
  the city and M is the number of roads.
  
  The following M lines describe one-way roads in the city. The i-th line
  (1-based) contains two integers X_i and Y_i (1 \leq X_i, Y_i \leq N, X_i \neq
  Y_i). X_i is the ID number (1-based) of the starting point of the i-th road
  and Y_i is that of the terminal point. The last line contains two integers S
  and T (1 \leq S, T \leq N, S \neq T, 1-based).
  
  The capacity of each road is 1. You can assume that i \neq j implies either
  X_i \neq X_j or Y_i \neq Y_j, and either X_i \neq Y_j or X_j \neq Y_i.
attempt: # AOJ 2304 Reverse Roads
  # Python3 2018.7.21 bal4u
  
  # *******************************************
  # Dinic's Max Flow Algorithm
  # *******************************************
  INF = 0x7FFFFFFF
  
  
  class Donic:
      def __init__(self, V):
          self.V = V
          self.level = [0] * V
          self.iter = [0] * V
          self.edge = [[] for i in range(V)]
  
      def add_edge(self, frm, to, cap):
          f, t = len(self.edge[frm]), len(self.edge[to])
          self.edge[frm].append([to, cap, t])
          self.edge[to].append([frm, cap, f])
  
      def bfs(self, s):
          self.level = [-1] * self.V
          self.level[s] = 0
          Q = []
          Q.append(s)
          while Q:
              v = Q.pop()
              for to, cap, rev in self.edge[v]:
                  if cap > 0 and self.level[to] < 0:
                      self.level[to] = self.level[v] + 1
                      Q.append(to)
  
      def dfs(self, v, t, f):
          if v == t:
              return f
          k = self.iter[v]
          while k < len(self.edge[v]):
              to, cap, rev = self.edge[v][k]
              if cap > 0 and self.level[v] < self.level[to]:
                  d = self.dfs(to, t, f if f <= cap else cap)
                  if d > 0:
                      self.edge[v][k][1] -= d
                      self.edge[to][rev][1] += d
                      return d
              self.iter[v] += 1
              k += 1
          return 0
  
      def maxFlow(self, s, t):
          flow = 0
          while True:
              self.bfs(s)
              if self.level[t] < 0:
                  break
              self.iter = [0] * self.V
              while True:
                  f = self.dfs(s, t, INF)
                  if f <= 0:
                      break
                  flow += f
          return flow
  
  
  N, M = map(int, input().split())
  dir = [[0 for j in range(N)] for i in range(N)]
  id = [[0 for j in range(N)] for i in range(N)]
  d = Donic(N)
  for i in range(M):
      x, y = map(int, input().split())
      x, y = x - 1, y - 1
      dir[y][x] = 1
      id[y][x] = i + 1
      d.add_edge(x, y, 1)
  S, T = map(int, input().split())
  print(d.maxFlow(S - 1, T - 1))
  
  ans = []
  for i in range(N):
      for to, cap, rev in d.edge[i]:
          if cap < 1 and dir[i][to]:
              ans.append(id[i][to])
  ans.sort()
  print(len(ans))
  print(*ans, sep="\n")
  
problem_description: Reverse Roads
  
  ICP city has an express company whose trucks run from the crossing S to the
  crossing T. The president of the company is feeling upset because all the
  roads in the city are one-way, and are severely congested. So, he planned to
  improve the maximum flow (edge disjoint paths) from the crossing S to the
  crossing T by reversing the traffic direction on some of the roads.
  
  Your task is writing a program to calculate the maximized flow from S to T by
  reversing some roads, and the list of the reversed roads.
samples: [{"input": "2 1\n    2 1\n    2 1", "output": "1\n    0"}, {"input": "2 1\n    1 2\n    2 1", "output": "1\n    1\n    1"}, {"input": "3 3\n    3 2\n    1 2\n    3 1\n    1 3", "output": "2\n    2\n    1\n    3"}]