题目链接:https://www.luogu.org/problemnew/show/P2820
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
static int n;
static int m;
static int[]parent;
static int[]rank;
static int a,b,c;
public static void init() {
for(int i=1;i<=n;i++) {
parent[i]=-1;
rank[i]=0;
}
}
public static int find_root(int x) {
int x_root=x;
while(parent[x_root]!=-1) {
x_root=parent[x_root];
}
return x_root;
}
public static int union(int x,int y) {
int x_root=find_root(x);