import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.NoSuchElementException; class DJSet { int n; int[] upper; public DJSet(int n) { this.n=n; upper=new int[n]; Arrays.fill(upper, -1); } int root(int x) { return upper[x]<0?x:(upper[x]=root(upper[x])); } boolean equiv(int x,int y) { return root(x)==root(y); } void unite(int x,int y) { x=root(x);y=root(y); if (x==y) return; if (upper[x][] g=new ArrayList[N]; for (int i=0;i(); int[] u=new int[N-1]; int[] v=new int[N-1]; int[] c=new int[N-1]; for (int i=0;ia[1])); for (int j=0;j+1 Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }