// See https://aka.ms/new-console-template for more information using System.Collections; using System.Runtime.InteropServices; internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List> G = new List>(n); for(int i=0;i()); for (int i = 0; i < n-1; i++) { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = line[0], b = line[1]; a--; b--; G[a].Add(b); G[b].Add(a); //Console.WriteLine("first edge {0} and {1}",a,b); } List cnt = new List(n); for (int i = 0; i < n; i++) cnt.Add(0); List mk = new List(n); for (int i = 0; i < n; i++) mk.Add(-1); int m = int.Parse(Console.ReadLine()); var v =Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); List exi = new List(n); for(int i=0;i ps = mkar(n, 0); for (int i = 0; i < n; i++) { if (cnt[i] == 1&&!exi[i]) { //Console.WriteLine("bad {0}",i); //Console.WriteLine(cnt[i]); ps[mk[i]]++; } } int preans = 0; for(int i=0;i0||exi[i]) preans++; //Console.WriteLine((preans)); for (int i = 0; i < n; i++) { //Console.WriteLine("adj {0}",ps[i]); } for (int i = 0; i < n; i++) { int ans = preans; //distance 2 for (int j = 0; j < G[i].Count(); j++) { int to = G[i][j]; ans -= ps[to]; } //Console.WriteLine("hello {0}", ans); if (cnt[i] == 1&&!exi[i]) ans++; //distance 0 if (exi[i]||cnt[i]>0) ans--; //Console.WriteLine("hello {0}", ans); //Console.WriteLine(exi[i]); //distance 1 for (int j = 0; j < G[i].Count(); j++) { int to = G[i][j]; if (cnt[to] == 1 && mk[to] == i) ans--; else if (cnt[to] == 0 && exi[to]) ans--; } Console.WriteLine(ans); } } public static List mkar(int n, int val) { List res = new List(n); for(int i=0;i