#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 size[],int u,int v){ size[find(p,u)] += size[find(p,v)]; p[find(p,v)] = find(p,u); } long long cal(int n){ long long black = 0; for(int i = 1; i <= n; i++){ int u = color[1][keep[i]]; //printf("u = %d: %d\n",u,size[1][u]); if(!vis[u]){ //printf("u = %d, size[1][u] = %d\n",u,size[1][u]); black += 1ll*size[1][u]; } vis[u] = 1; } std::sort(keep+1,keep+1+n,[&](int& u,int& v){ return color[1][u]