#include #include #include int p[2][100005]; int size[2][100005]; int e[100005]; int color[2][100005]; int keep[100005]; int vis[100005]; int find(int p[],int u){ if(p[u]==u) return u; else return p[u] = find(p,p[u]); } void merge(int p[],int count[],int u,int v){ //equal should return ! int x = find(p,u), y = find(p,v); if(x==y) return ; count[x] += count[y]; p[y] = x; } long long cal(int n){ long long black = 0; for(int i = 1; i <= n; i++){ int u = color[1][keep[i]]; if(!vis[u]){ black += 1ll*size[1][u]; } vis[u] = 1; } for(int i = 1; i <= n; i++){ int u = color[1][keep[i]]; vis[u] = 0; } return (black-1)*1ll*n; } int main(){ int n,a,b; scanf("%d%d%d",&n,&a,&b); for(int i = 1; i <= n; i++){ p[0][i] = p[1][i] = i; size[0][i] = size[1][i] = 1; e[i] = i; } for(int i = 1; i <= a; i++){ int u,v; scanf("%d%d",&u,&v); merge(p[0],size[0],u,v); } for(int i = 1; i <= b; i++){ int u,v; scanf("%d%d",&u,&v); merge(p[1],size[1],u,v); } for(int i = 1; i <= n; i++){ color[0][i] = find(p[0],i); color[1][i] = find(p[1],i); //printf("i = %d: %d %d\n",i,color[0][i],color[1][i]); } std::sort(e+1,e+1+n,[&](int& u,int& v){ return color[0][u]