#include using namespace std; int find(int X,vector &P){ if(P.at(X)<0){ return X; } return P.at(X)=find(P.at(X),P); } void unite(int X,int Y,vector &P){ X=find(X,P); Y=find(Y,P); if(X==Y){ return; } if(P.at(X)P.at(Y)){ P.at(Y)+=P.at(X); P.at(X)=Y; } else if(X> N >> M; vector P(N,-1); for(int i=0;i> A >> B; unite(A-1,B-1,P); } for(int i=0;i