import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] ne = new int[N]; int[] ha = new int[N]; for(int i=0;i> g = new ArrayList<>(); for(int i=0;i()); for(int i=1;i ne_list = new ArrayList<>(); for(int i=1;i que_l = new LinkedList<>(); Queue que_num = new LinkedList<>(); que_l.add(0); que_num.add(0); while(!que_l.isEmpty()){ int now = que_l.poll(); int num = que_num.poll(); ne[now]=num; for(int i=0;i(); que_num = new LinkedList<>(); que_l.add(j); que_num.add(0); while(!que_l.isEmpty()){ int now = que_l.poll(); int num = que_num.poll(); ha[now]=num; for(int i=0;i