lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end class Solve @n : Int32 @g = Array(Array(Tuple(Int32, Int32))).new @edges = [] of Tuple(Int32, Int32) @in_loop : Int32? def initialize @n = read_line.to_i @g = (1..@n).map { Array(Tuple(Int32, Int32)).new } @n.times do |i| a, b = read_line.split.map(&.to_i.pred) @g[a] << {b, i} @g[b] << {a, i} @edges << {a, b} end @flag = Array(Int32?).new(@n, nil) end def dfs(v, prev, prev_edge) if @flag[v] @in_loop = v @flag[v] = prev_edge return end @flag[v] = prev_edge @g[v].each do |(u, i)| next if u == prev || @in_loop dfs(u, v, i) end end def solve dfs(0, -1, -1) ans = [] of Int32 now = @in_loop.not_nil! while now != @in_loop || ans.empty? edge_i = @flag[now].not_nil! ans << edge_i + 1 u, v = @edges[edge_i] now = u == now ? v : u end puts ans.size, ans.sort.join(' ') end end solve = Solve.new solve.solve