Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.

Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most d kilometers along the roads. [Image] 

There are n cities in the country, numbered from 1 to n, connected only by exactly n - 1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has k police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city.

However, Zane feels like having as many as n - 1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible.

Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads.


-----Input-----

The first line contains three integers n, k, and d (2 ≤ n ≤ 3·10^5, 1 ≤ k ≤ 3·10^5, 0 ≤ d ≤ n - 1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.

The second line contains k integers p_1, p_2, ..., p_{k} (1 ≤ p_{i} ≤ n) — each denoting the city each police station is located in.

The i-th of the following n - 1 lines contains two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}) — the cities directly connected by the road with index i.

It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within d kilometers.


-----Output-----

In the first line, print one integer s that denotes the maximum number of roads that can be shut down.

In the second line, print s distinct integers, the indices of such roads, in any order.

If there are multiple answers, print any of them.


-----Examples-----
Input
6 2 4
1 6
1 2
2 3
3 4
4 5
5 6

Output
1
5

Input
6 3 2
1 5 6
1 2
1 3
1 4
1 5
5 6

Output
2
4 5 


-----Note-----

In the first sample, if you shut down road 5, all cities can still reach a police station within k = 4 kilometers.

In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line.

Source: codeforces | Difficulty: HARD
Tags: Graph algorithms

Graph traversal

Shortest paths

Constructive algorithms

Tree algorithms

Dynamic programming


Solutions:
import math
import sys
input = sys.stdin.readline
inf = int(1000000000.0)
(n, m, d) = list(map(int, input().split()))
l = [0] * (n - 1)
r = [0] * (n - 1)
g = [[] for _ in range(n)]
station = [int(_) - 1 for _ in input().split()]
for i in range(n - 1):
	(l[i], r[i]) = [int(i) - 1 for i in input().split()]
	g[l[i]].append(i)
	g[r[i]].append(i)
queue = []
dist = [inf] * n
need = [True] * (n - 1)
for i in station:
	queue.append(i)
	dist[i] = 0
cur = 0
while cur < len(queue):
	(x, cur) = (queue[cur], cur + 1)
	for edge in g[x]:
		y = l[edge] ^ r[edge] ^ x
		if dist[y] > 1 + dist[x]:
			dist[y] = 1 + dist[x]
			queue.append(y)
			need[edge] = False
print(sum(need))
edgeList = []
for i in range(n - 1):
	if need[i]:
		edgeList.append(str(i + 1))
print(' '.join(edgeList))


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
(n, k, d) = mapi()
plc = list(mapi())
gr = defaultdict(list)
for i in range(1, n):
	(u, v) = mapi()
	gr[u].append([v, i])
	gr[v].append([u, i])
q = deque()
for i in plc:
	q.append((i, 0))
vis = {}
res = [0] * (n + 1)
while q:
	(tmp, par) = q.popleft()
	if tmp in vis:
		continue
	vis[tmp] = 1
	for item in gr[tmp]:
		if item[0] != par:
			if item[0] in vis:
				res[item[1]] = 1
			else:
				q.append((item[0], tmp))
cnt = 0
ans = []
for i in range(1, n + 1):
	if res[i] == 1:
		cnt += 1
		ans.append(i)
print(cnt)
print(*ans)


from collections import deque

def bfs(graph, alphas):
	ans = set()
	n = len(graph)
	q = deque([alpha for alpha in alphas])
	used = [False] * n
	for alpha in q:
		used[alpha] = True
	(dist, parents) = ([0] * n, [-1] * n)
	while q:
		v = q.popleft()
		for u in graph[v]:
			if not used[u]:
				used[u] = True
				q.append(u)
				dist[u] = dist[v] + 1
				parents[u] = v
			elif v != parents[u] and u != parents[v]:
				(x, y) = (str(u) + ',' + str(v), str(v) + ',' + str(u))
				if x not in ans and y not in ans:
					ans.add(x)
	return ans

def shortest_path(graph, alpha, omega):
	(used, dist, parents) = bfs(graph, alpha)
	if not used[omega]:
		return []
	path = [omega]
	v = omega
	while parents[v] != -1:
		path += [parents[v]]
		v = parents[v]
	return path[::-1]
import os
import sys
from io import BytesIO, IOBase
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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	(n, k, d) = map(int, input().split())
	police = list(map(int, input().split()))
	graph = [[] for __ in range(n + 1)]
	di = {}
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		graph[x] += [y]
		graph[y] += [x]
		di[str(x) + ',' + str(y)] = i + 1
		di[str(y) + ',' + str(x)] = i + 1
	ans = bfs(graph, police)
	print(len(ans))
	print(*[di[k] for k in ans])