Problem:
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.

Input

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.

Output

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.

Sample Input 1

2 1
2 1
2 1

Output for the Sample Input 1

1
0

Sample Input 2

2 1
1 2
2 1

Output for the Sample Input 2

1
1
1

Sample Input 3

3 3
3 2
1 2
3 1
1 3

Output for the Sample Input 3

2
2
1
3

Solution in Ruby (judge verdict: Accepted)

module Graphical
	require 'set'

	def reachable_from(s, max_depth = nil)
		reached = Set[s]
		queue = [s]
		depth = 0
		loop {
			break if max_depth && depth >= max_depth
			next_queue = []
			until queue.empty?
				u = queue.shift
				each_out_connection_of(u){|v, _|
					next if reached.include?(v)
					reached << v
					next_queue << v
				}
			end
			break if next_queue.empty?
			queue = next_queue
			depth += 1
		}
		return reached
	end

	def bfs(start)
		raise "start must be Enumerable" if !start.kind_of?(Enumerable)
		reached = Set[*start.to_a]
		queue = []
		start.each{|s| queue << s}
		dist = {}
		loop.with_index {|_, depth|
			next_queue = []
			until queue.empty?
				u = queue.shift
				return depth if block_given? && yield(u, depth)
				dist[u] = depth
				each_out_connection_of(u){|v, _|
					next if reached.include?(v)
					reached << v
					next_queue << v
				}
			end
			break if next_queue.empty?
			queue = next_queue
		}
		return dist
	end

	def dijkstra(start)
		raise "start must be Enumerable" if !start.kind_of?(Enumerable)
		h = Heap.new
		reached = Set[*start.to_a]
		start.each{|s| h.add(s, 0)}

		dist = {}
		until h.empty?
			u, key = h.del_min
			return key if block_given? && yield(u, key)
			dist[u] = key
			each_out_connection_of(u){|v, l|
				d = dist[u] + l
				if reached.include?(v)
					h.update_key(v, d)
				else
					h.add(v, d)
					reached << v
				end
			}
		end
		block_given? ? nil : dist
	end

	def bidir_dijkstra(s, t)
		f_dist = {}
		b_dist = {}

		f_heap = Heap.new
		b_heap = Heap.new

		f_heap.add(s, 0)
		b_heap.add(t, 0)

		f_reached = Set[s]
		b_reached = Set[t]

		f_current_dist = b_current_dist = 0
		best = Float::INFINITY

		loop {
			if !f_heap.empty?
				u, key = f_heap.del_min
				f_dist[u] = key
				f_current_dist = key
				each_out_connection_of(u){|v, l|
					d = f_dist[u] + l
					if b_dist[v]
						path_len = d + b_dist[v]
						best = path_len if path_len < best
					end
					if f_reached.include?(v)
						f_heap.update_key(v, d)
					else
						f_heap.add(v, d)
						f_reached << v
					end
				}
			end

			if !b_heap.empty?
				u, key = b_heap.del_min
				b_dist[u] = key
				b_current_dist = key
				each_in_connection_of(u){|v, l|
					d = b_dist[u] + l
					if f_dist[v]
						path_len = d + f_dist[v]
						best = path_len if path_len < best
					end
					if b_reached.include?(v)
						b_heap.update_key(v, d)
					else
						b_heap.add(v, d)
						b_reached << v
					end
				}
			end

			return best if f_current_dist + b_current_dist >= best
			return nil if f_heap.empty? && b_heap.empty?
		}
	end

	def a_star(start)
		raise "a_star need termination condition" unless block_given?
		h = Heap.new
		reached = Set[start]
		h.add(start, [a_star_heuristic(start), 0])

		dist = {}
		until h.empty?
			u, (e, d) = h.del_min
			return d if yield(u, dist)
			dist[u] = d
			each_out_connection_of(u){|v, l|
				d = dist[u] + l
				e = d + a_star_heuristic(v)
				if reached.include?(v)
					h.update_key(v, [e, d])
				else
					h.add(v, [e, d])
					reached << v
				end
			}
		end
		block_given? ? nil : dist
	end

	#make_variations :bidir_dijkstra

	def prim(start)
		h = Heap.new
		h.add(start, 0)
		reached = Set[start]
		tree_len = 0

		until h.empty?
			u, key = h.del_min
			tree_len += key

			each_connection_of(u){|v, d|
				if reached.include?(v)
					h.update_key(v, d)
				else
					h.add(v, d)
					reached << v
				end
			}
		end
		tree_len
	end

	def each_layer_from(start)
		raise "start must be Enumerable" if !start.kind_of?(Enumerable)
		return enum_for(__method__, start) unless block_given?
		reached = Set[*start]
		current_layer = start

		loop {
			yield current_layer
			next_layer = []
			current_layer.each{|u|
				each_out_connection_of(u){|v|
					next if reached.include?(v)
					reached << v
					next_layer << v
				}
			}	

			return if next_layer.empty?
			current_layer = next_layer
		}
	end
end

class Graph
	include Graphical

	def initialize(*options)
		@options = Set[*options]
	end

	def add_node(property = {})
		Node.new(property)
	end

	def add_edge(u, v, property = {})
		e = Edge.new(u, v, property)
		u.add_edge(e)
		v.add_edge(e)
		e
	end
	
	def del_edge(e)
		u, v = e.opposite.keys
		u.del_edge(e)
		v.del_edge(e)
		e
	end

	class Node
		def initialize(property)
			@property = property
			@edges = Set.new
		end

		def add_edge(e)
			@edges << e
		end

		def del_edge(e)
			@edges.delete(e)
		end

		def to_s
			@property[:name] || super
		end

		def each_edge
			@edges.each{|e| 
				yield e
			}
		end

		attr_reader :property
	end

	class Edge
		def initialize(u, v, property)
			@opposite = {u => v, v => u}
			@property = property
		end
		attr_reader :opposite, :property

		def to_s
			@property[:name] || super
		end

		def length
			@property[:length] || 1
		end
	end

	def each_out_connection_of(u)
		u.each_edge{|e|
			yield(e.opposite[u], e.length)
		}
	end

	alias :each_in_connection_of :each_out_connection_of

	def get_path_by_bfs(s, t)
		path_edge = {}
		reached = Set[s]
		queue = [s]
		while !queue.empty? 
			u = queue.shift
			u.each_edge{|e|
				v = e.opposite[u]
				next if reached.include?(v)	
				reached << v
				queue << v
				path_edge[v] = e

				if v == t
					path = []
					while e = path_edge[v]
						path.unshift e
						v = e.opposite[v]
					end
					path.unshift s
					return path
				end
			}
		end	
		return nil
	end
end

class Digraph < Graph
	def add_node(property = {})
		Node.new(property)
	end

	def add_edge(u, v, property = {})
		e = Edge.new(u, v, property)
		u.add_out_edge(e)
		v.add_in_edge(e)
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.out_edges.delete(e)
		v.in_edges.delete(e)
		e
	end

	class Node < Graph::Node
		def initialize(property)
			@property = property
			@out_edges = Set.new
			@in_edges = Set.new
		end

		def add_out_edge(e)
			@out_edges << e
		end

		def del_out_edge(e)
			@out_edges.delete(e)
		end

		def add_in_edge(e)
			@in_edges << e
		end

		def del_in_edge(e)
			@in_edges.delete(e)
		end

		attr_reader :in_edges, :out_edges
	end

	class Edge < Graph::Edge
		def initialize(u, v, property)
			@from = u	
			@to = v
			@property = property
		end

		attr_reader :from, :to
	end

	def each_out_connection_of(u)
		u.out_edges.each{|e|
			yield [e.to, e.length]
		}
	end

	def each_in_connection_of(v)
		v.in_edges.each{|e|
			yield [e.from, e.length]
		}
	end

#----------------------------------------------------------


	def get_path_dfs(s, t, reached = Set.new)
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			return [e] if v == t
			
			path = get_path_dfs(v, t, reached) 
			return [e] + path if path
		}
		nil
	end

end

n, m = gets.split.map &:to_i

g = Graph.new
nodes = (0..n).map{|i| g.add_node({:name => i})}
edges = []

orig_dest = {}
(1..m).each{|k|
	i, j = gets.split.map &:to_i
	e = g.add_edge(nodes[i], nodes[j] , {:name => k})
	edges << e
	orig_dest[e] = nodes[j]
}


s, t = gets.split.map &:to_i

def augment_path(s, t)
	path_edge = {}
	reached = Set[s]
	queue = [s]
	while !queue.empty? 
		u = queue.shift
		u.each_edge{|e|
			v = e.opposite[u]
			next if reached.include?(v)	

			flow = (e.property[:flow] ||= {:destination => v, :amount => 0})
			next if flow[:destination] == v && flow[:amount] == 1

			reached << v
			queue << v
			path_edge[v] = e

			if v == t
				path = []
				while e = path_edge[v]
					path.unshift e
					v = e.opposite[v]
				end
				path.unshift s
				return path
			end
		}
	end	
	return nil
end


def send_flow_along(path)
	u, *edges = path
	edges.each{|e|
		v = e.opposite[u]
		flow = (e.property[:flow] ||= {:destination => v, :amount => 0})
		if flow[:destination] == v
			flow[:amount] += 1
		elsif flow[:amount] == 0
			flow[:destination] = v
			flow[:amount] = 1
		else
			flow[:amount] -= 1
		end
		u = v
	}
end

c = 0
while path = augment_path(nodes[s], nodes[t])
	send_flow_along(path)
	c += 1
end

reversed = []
edges.each{|e|
	flow = e.property[:flow]
	if flow && flow[:destination] != orig_dest[e]
		reversed << e.property[:name]
	end
}

puts c
puts reversed.size
puts reversed