private static int gcd(int a, int b) {
return (b == 0) ? a : gcd(b, a % b);
}
private static int qpow(int a, int b, int p) {
int res = (int) 1;
while (b > 0) {
if ((b & 1) == 1) {
res = res * a % p;
}
a = a * a % p;
b >>= 1;
}
return res;
}
private static int find(int x) {
return (int) ((x == f[x]) ? x : (f[x] = find(f[x])));
}
private static void merge(int x, int y) {
int f1 = find(x);
int f2 = find(y);
f[f1] = f2;
}
for (int i = 1; i <= n; i ++ ) {
for (int j = 1; j <= n; j ++ ) {
if (i == j) {
g[i][j] = 0;
} else {
g[i][j] = INF;
}
}
}
private static void floyd() {
for (int k = 1; k <= n; k ++ ) {
for (int i = 1; i <= n; i ++ ) {
for (int j = 1; j <= n; j ++ ) {
g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
}
}
}
}
private static int kruskal() {
int res = 0;
int cnt = 0;
Arrays.sort(edges, 1, m + 1);
for (int i = 1; i <= n; i ++ ) {
p[i] = i;
}
for (int i = 1; i <= m; i ++ ) {
int u = edges[i].u;
int v = edges[i].v;
int w = edges[i].w;
int f1 = find(u);
int f2 = find(v);
if (f1 != f2) {
p[f1] = f2;
res += w;
cnt ++ ;
}
}
if (cnt < n - 1) {
return INF;
}
return res;
}
private static int find(int x) {
return (x == p[x]) ? x : (p[x] = find(p[x]));
}
class node implements Comparable<node> {
public int u;
public int v;
public int w;
node(int u, int v, int w) {
this.u = u;
this.v = v;
this.w = w;
}
@Override
public int compareTo(node o) {
return Integer.compare(w, o.w);
}
}