The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.

The council of the elders has recently decided to choose the capital of Treeland. Of course it should be a city of this country. The council is supposed to meet in the capital and regularly move from the capital to other cities (at this stage nobody is thinking about getting back to the capital from these cities). For that reason if city a is chosen a capital, then all roads must be oriented so that if we move along them, we can get from city a to any other city. For that some roads may have to be inversed.

Help the elders to choose the capital so that they have to inverse the minimum number of roads in the country.

Input

The first input line contains integer n (2 ≤ n ≤ 2·105) — the number of cities in Treeland. Next n - 1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers si, ti (1 ≤ si, ti ≤ n; si ≠ ti) — the numbers of cities, connected by that road. The i-th road is oriented from city si to city ti. You can consider cities in Treeland indexed from 1 to n.

Output

In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order.

Examples

Input

3
2 1
2 3


Output

0
2 


Input

4
1 4
2 4
3 4


Output

2
1 2 3

Difficulty: MEDIUM_HARD

Solutions:
import sys
from collections import defaultdict
from typing import NamedTuple

class EdgeNode(NamedTuple):
	vertex: int
	weight: int

class Graph:

	def __init__(self, n):
		self.graph = d = {i: [] for i in range(n + 1)}
		self.distance = [0] * (n + 1)
		self.distance[0] = sys.maxsize
		self.min_dist = sys.maxsize
		self.summation = n * (n + 1) / 2

	def dfs(self, root, visited=defaultdict(bool)):
		(stack, path) = ([root], [])
		rev = 0
		visited[root] = True
		while stack:
			s = stack.pop()
			visited[s] = True
			for v in self.graph[s]:
				if v[0] not in visited:
					dist = self.distance[s] + v[1]
					if dist < self.min_dist:
						self.min_dist = dist
					self.distance[v[0]] = dist
					self.summation -= v[0]
					if v[1] == -1:
						rev += 1
					path.append(s)
					stack.append(v[0])
		return rev

	def get_min_distance(self):
		return min(self.distance)

def main():
	n = int(input())
	g = Graph(n)
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		g.graph[x].append([y, 1])
		g.graph[y].append([x, -1])
	total_rev = g.dfs(1)
	min_distance = 0 if g.summation > 0 and g.min_dist > 0 else g.min_dist
	print(total_rev + min_distance)
	join = ' '.join(map(str, [i for i in range(n + 1) if g.distance[i] == min_distance]))
	print(join)
main()


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
from collections import defaultdict

def main():
	n = int(input())
	tree = [[] for _ in range(n + 1)]
	path = [set() for _ in range(n + 1)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		tree[a].append(b)
		tree[b].append(a)
		path[a].add(b)
	dist = [0] * (n + 1)
	d = defaultdict(int)
	stack = [(1, 0, 0)]
	idx = [0] * (n + 1)
	totalGreen = 0
	while stack:
		(x, p, g) = stack[-1]
		y = idx[x]
		if y == len(tree[x]):
			d[x] = g
			stack.pop()
		else:
			z = tree[x][y]
			if z != p:
				if z in path[x]:
					g += 1
					totalGreen += 1
				stack.append((z, x, g))
				dist[z] = 1 + dist[x]
			idx[x] += 1
	totalRed = n - 1 - totalGreen
	res = [0] * (n + 1)
	ans = 10 ** 10
	for i in range(1, n + 1):
		res[i] = (d[i] << 1) + totalRed - dist[i]
		ans = min(ans, res[i])
	print(ans)
	for i in range(1, n + 1):
		if res[i] == ans:
			print(i, end=' ')
	print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
input = stdin.readline
n = int(input())
mn = n
(e, down, up) = ({(1, 0)}, [0] * (n + 1), [0] * (n + 1))
g = {x: [] for x in range(1, n + 1)}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	e.add((a, b))
	g[a].append(b)
	g[b].append(a)
q = [(0, 1)]
trav = [(0, 1)]
while q:
	(p, v) = q.pop()
	for ch in g[v]:
		if ch != p:
			q.append((v, ch))
			trav.append((v, ch))
for (p, v) in trav[::-1]:
	down[v] = sum((down[ch] + ((v, ch) not in e) for ch in g[v] if ch != p))
up[0] = down[1] + 1
q = [(0, 1)]
while q:
	(p, v) = q.pop()
	up[v] = down[p] + up[p] - down[v] + [1, -1][(v, p) in e]
	if down[v] + up[v] < mn:
		(ans, mn) = ([v], down[v] + up[v])
	elif down[v] + up[v] == mn:
		ans.append(v)
	for ch in g[v]:
		if ch != p:
			q.append((v, ch))
print(mn)
stdout.write(' '.join((str(i) for i in sorted(ans))))


from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write

def in_arr():
	return map(int, raw_input().split())

def pr_num(n):
	stdout.write(str(n) + '\n')

def pr_arr(arr):
	pr(' '.join(map(str, arr)) + '\n')
n = int(raw_input())
d = [[] for i in range(n + 1)]
for i in range(n - 1):
	(u, v) = in_arr()
	d[u].append((v, 0))
	d[v].append((u, 1))
totr = 0
dp = [[0, 0] for i in range(n + 1)]
q = [1]
vis = [0] * (n + 1)
vis[1] = 1
q = [1]
pos = 0
while pos < n:
	x = q[pos]
	pos += 1
	for (i, w) in d[x]:
		if not vis[i]:
			vis[i] = 1
			q.append(i)
			dp[i][0] = dp[x][0] + 1
			dp[i][1] = dp[x][1]
			if w:
				totr += 1
				dp[i][1] += 1
mn = 10 ** 18
for i in range(1, n + 1):
	temp = totr - 2 * dp[i][1] + dp[i][0]
	mn = min(mn, temp)
pr_num(mn)
for i in range(1, n + 1):
	temp = totr - 2 * dp[i][1] + dp[i][0]
	if temp == mn:
		pr(str(i) + ' ')


n = int(input())
t = [0] * (n + 1)
(u, v) = ([[] for i in range(n + 1)], [[] for i in range(n + 1)])
for i in range(n - 1):
	(a, b) = map(int, input().split())
	t[b] = 1
	u[a].append(b)
	v[b].append(a)
(d, s) = (u[1] + v[1], len(v[1]))
for i in u[1]:
	t[i] = 1
	v[i].remove(1)
for i in v[1]:
	t[i] = -1
	u[i].remove(1)
while d:
	b = d.pop()
	(x, y) = (t[b] + 1, t[b] - 1)
	for i in u[b]:
		t[i] = x
		v[i].remove(b)
	for i in v[b]:
		t[i] = y
		u[i].remove(b)
	d += u[b] + v[b]
	s += len(v[b])
m = min(t)
print(s + m)
print(' '.join(map(str, [i for i in range(1, n + 1) if t[i] == m])))


import os
import sys
from io import BytesIO, IOBase
from collections import deque

def main():
	n = int(input())
	tree = [[] for _ in range(n + 1)]
	path = [set() for _ in range(n + 1)]
	straight = [0] * (n + 1)
	reverse = [0] * (n + 1)
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		tree[a].append(b)
		tree[b].append(a)
		path[a].add(b)
	idx = [0] * (n + 1)
	root = [(1, 0)]
	totalrev = 0
	while root:
		(x, p) = root[-1]
		y = idx[x]
		if y == len(tree[x]):
			root.pop()
		else:
			z = tree[x][y]
			if z != p:
				root.append((z, x))
				if z not in path[x]:
					reverse[z] = 1 + reverse[x]
					straight[z] = straight[x]
					totalrev += 1
				else:
					reverse[z] = reverse[x]
					straight[z] = 1 + straight[x]
			idx[x] += 1
	ans = totalrev
	arr = [1]
	for i in range(2, n + 1):
		temp = totalrev - reverse[i] + straight[i]
		if ans > temp:
			ans = temp
			arr = [i]
		elif ans == temp:
			arr.append(i)
	print(ans)
	print(*arr)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(2 * 10 ** 5)

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

@bootstrap
def dfs(u, p):
	for j in adj[u]:
		if j != p:
			yield dfs(j, u)
			val[u] += val[j] + d[u, j]
	yield

@bootstrap
def dfs2(u, p, v):
	ans[u] = val[u] + v
	for j in adj[u]:
		if j != p:
			yield dfs2(j, u, val[u] - val[j] - d[u, j] + v + d[j, u])
	yield
n = int(input())
adj = [[] for i in range(n + 1)]
d = dict()
for j in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u].append(v)
	adj[v].append(u)
	d[u, v] = 0
	d[v, u] = 1
val = [0] * (n + 1)
dfs(1, 0)
ans = [0] * (n + 1)
d[1, 0] = 0
dfs2(1, 0, 0)
m = min(ans[1:])
res = []
for j in range(1, n + 1):
	if ans[j] == m:
		res.append(j)
print(m)
print(*res)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def redOfTree(node, parent, g):
	count = 0
	for (v, c) in g[node]:
		if v != parent:
			count += c + redOfTree(v, node, g)
	return count

def solve(N, A):
	INF = N + 100
	flips = [INF for _ in range(N + 1)]
	q = [(1, 0, 0)]
	redCount = 0
	flips[1] = 0
	while q:
		nq = []
		for (node, red, dist) in q:
			for (v, c) in A[node]:
				if flips[v] == INF:
					redCount += c
					(ndist, nred) = (dist + 1, red + c)
					flips[v] = ndist - 2 * nred
					nq.append((v, nred, ndist))
		q = nq
	mf = min(flips)
	vertex = [i for (i, v) in enumerate(flips) if v == mf]
	print(redCount + mf)
	print(' '.join(map(str, vertex)))
N = int(input())
A = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(u, v) = map(int, input().split())
	A[u].append((v, 0))
	A[v].append((u, 1))
solve(N, A)


from math import sqrt, gcd, ceil, floor, log, factorial
from itertools import permutations, combinations
from collections import Counter, defaultdict
import collections, sys, threading
import collections, sys, threading
sys.setrecursionlimit(10 ** 9)
threading.stack_size(10 ** 8)

def solve():

	def dfs_red(node, par, dire, undire, dist, path_red, red):
		dist[node] = 1 + dist[par]
		if par in dire[node]:
			path_red[node] = 1 + path_red[par]
			red.append(1)
		else:
			path_red[node] = path_red[par]
		for i in undire[node]:
			if i != par:
				dfs_red(i, node, dire, undire, dist, path_red, red)

	def ii():
		return int(input())

	def si():
		return input()

	def mi():
		return map(int, input().split())

	def msi():
		return map(str, input().split())

	def li():
		return list(mi())
	n = ii()
	dire = defaultdict(list)
	undire = defaultdict(list)
	(dist, path_red) = ({}, {})
	dist[0] = -1
	path_red[0] = 0
	for _ in range(n - 1):
		(u, v) = mi()
		dire[u].append(v)
		undire[u].append(v)
		undire[v].append(u)
	red = []
	dfs_red(1, 0, dire, undire, dist, path_red, red)
	totred = len(red)
	ans = 10 ** 9
	res = [0]
	fin = []
	for i in range(1, n + 1):
		res.append(totred - 2 * path_red[i] + dist[i])
		ans = min(ans, totred - 2 * path_red[i] + dist[i])
	for i in range(1, n + 1):
		if res[i] == ans:
			fin.append(i)
	print(ans)
	print(*fin)
threading.Thread(target=solve).start()