#include<bits/stdc++.h>
using namespace std;
const int N = 5000;
int fa[N];
int find(int x){
if(x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
void merge_set(int x, int y){
int a = find(x), b = find(y);
if(a == b) return;
fa[a] = b;
}
int main...