import java.util.*; public class Main { static int par[];//mainでparのi代入が必要 static int rank[]; static int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } static boolean same(int x, int y) { return find(x) == find(y); } static void union(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int d[]=new int[n]; int w[]=new int[n]; for(int i=0;iparent[]=new ArrayList[n]; for(int i=0;i(); } for(int i=0;i