import java.io.*; import java.util.*; public class Main { static ArrayList> graph = new ArrayList<>(); static ArrayList> part = new ArrayList<>(); static int[] counts; static int k; static int base; static int total = 0; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); k = sc.nextInt(); counts = new int[n]; for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); part.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a); } for (int i = 0; i < k; i++) { counts[sc.nextInt() - 1] = 1; } getCount(0, 0); PriorityQueue queue = new PriorityQueue<>(); int[] costsA = new int[n]; queue.add(new Path(base, 0)); doBTS(queue, costsA); int maxA = 0; int maxAIdx = 0; for (int i = 0; i < n; i++) { if (costsA[i] < Integer.MAX_VALUE && maxA < costsA[i]) { maxA = costsA[i]; maxAIdx = i; } } int[] costsB = new int[n]; queue.add(new Path(maxAIdx, 0)); doBTS(queue, costsB); int maxB = 0; int maxBIdx = 0; for (int i = 0; i < n; i++) { if (costsB[i] < Integer.MAX_VALUE && maxB < costsB[i]) { maxB = costsB[i]; maxBIdx = i; } } int[] costsC = new int[n]; queue.add(new Path(maxBIdx, 0)); doBTS(queue, costsC); int maxC = 0; int maxCIdx = 0; for (int i = 0; i < n; i++) { if (costsC[i] < Integer.MAX_VALUE && maxC < costsC[i]) { maxC = costsC[i]; maxCIdx = i; } } for (int i = 0; i < n; i++) { if (costsA[i] == Integer.MAX_VALUE) { continue; } queue.add(new Path(i, total * 2 - Math.max(costsB[i], costsC[i]))); } int[] ans = new int[n]; Arrays.fill(ans, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (ans[p.idx] <= p.value) { continue; } ans[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } StringBuilder sb = new StringBuilder(); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } static int getCount(int idx, int p) { if (counts[idx] == 1) { base = idx; } for (int x : graph.get(idx)) { if (x == p) { continue; } int tmp = getCount(x, idx); if (tmp > 0 && tmp < k) { part.get(idx).add(x); part.get(x).add(idx); total++; } counts[idx] += tmp; } return counts[idx]; } static void doBTS(PriorityQueue queue, int[] costs) { Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : part.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }