import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.Scanner; public class Main { private static HashSet<Integer> infected; private static HashSet<Integer>[] adj; private static int t; public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ solution(in); } } /** * 模拟法: bfs * @param in */ private static void solution(Scanner in){ // 点数 int V = in.nextInt(); // 边数 int E = in.nextInt(); // 构建图 点的范围[1:V] adj = new HashSet[V+1]; for(int i=1; i<=V; i++){ adj[i] = new HashSet<>(); } int v1,v2; for(int i=1; i<=E; i++){ v1 = in.nextInt(); v2 = in.nextInt(); // 去环 if(v1 != v2){ adj[v1].add(v2); adj[v2].add(v1); } } // 感染病毒的点集infected int k = in.nextInt(); t = in.nextInt(); infected = new HashSet<>(); for(int i=1; i<=k; i++){ infected.add(in.nextInt()); } // bfs List<Integer> result = new ArrayList<>(); for(int i=1; i<=V; i++){ if(bfs(i)){ result.add(i); } } // 输出 if(result.size() == 0){ System.out.println(-1); }else{ int size = result.size(); for(int i=0; i<size-1; i++){ System.out.print(result.get(i)); System.out.print(" "); } System.out.print(result.get(size-1)); } } /** * 广度优先搜索 * @param start * @return */ private static boolean bfs(int start){ HashSet<Integer> visited = new HashSet<>(); Queue<Integer> queue = new LinkedList<>(); if(infected.contains(start)){ visited.add(start); queue.offer(start); } int days = 0; while(!queue.isEmpty()){ Integer u; for(int i=queue.size(); i > 0; i--){ u = queue.poll(); for(Integer v: adj[u]){ if(!infected.contains(v)){ return false; }else if(!visited.contains(v)){ visited.add(v); queue.offer(v); } } } if(++days == t){ break; } } return visited.size() == infected.size(); } }