just like the title says, and I just can’t figure out why. Any help would be great, thank you.
import java.io.*;
//@author Maurice Saldivar
public class Main {
public static int uf[];
public static void union (int x, int y) throws Exception{
uf[find(x)] = find(y);
}
//path compression for faster find
public static int find (int x) throws Exception{
if (uf[x] != uf[uf[x]]) {
uf[x] = find(uf[x]);
}
return uf[x];
}
public static void main(String[] args) throws Exception {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out, true);
String tokens[];
int T = Integer.parseInt(br.readLine());
for (int i = 0; i < T; ++i) {
tokens = br.readLine().split("\\s+");
int N = Integer.parseInt(tokens[0]);
int M = Integer.parseInt(tokens[1]);
uf = new int[N + 1];
for (int j = 1; j <= N; ++j) {
uf[j] = j;
}
for (int j = 0; j < M; ++j) {
tokens = br.readLine().split("\\s+");
int X = Integer.parseInt(tokens[0]);
int Y = Integer.parseInt(tokens[1]);
union(X, Y);
}
long employeeSize[] = new long[N + 1];
for (int j = 1; j <= N; ++j) {
int index = find(j);
employeeSize[index]++;
}
int maxEscapes = 0;
long answer = 1;
for (int j = 1; j <= N; ++j) {
if (employeeSize[j] > 0) {
maxEscapes++;
answer = (answer * employeeSize[j]) % 1000000007;
}
}
pw.println(maxEscapes + " " + answer);
}
} catch (Exception e) {
return;
}
}
}