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<>(); boolean[] check = new boolean[N]; que_l.add(0); que_num.add(0); while(!que_l.isEmpty()){ int now = que_l.poll(); int num = que_num.poll(); check[now]=true; ha[now]=Math.min(ha[now], num); for(int i=0;i(); que_num = new LinkedList<>(); check = new boolean[N]; que_l.add(j); que_num.add(0); while(!que_l.isEmpty()){ int now = que_l.poll(); int num = que_num.poll(); check[now]=true; ne[now]=Math.min(ne[now], num); for(int i=0;i