并查集好合并不好拆开 可以考虑离线 先读入 从大到小排序 再依次合并
技巧:不好断开就倒着来合并 JSOI2008 P1197 也是该思想
#includeusing namespace std;#define Max(x,y) (x)<(y)?(y):(x)#define Min(x,y) (x)<(y)?(x):(y)#define ll long long#define rg registerconst int N=300000+5,M=1000000+5,inf=0x3f3f3f3f,P=9999973;int n,m,f[N],sz[N];template void rd(t &x){ x=0;int w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=w?-x:x;}int find(int x) { return f[x]==x?x:f[x]=find(f[x]);}void merge(int x,int y){ int fx=find(x),fy=find(y); if(fx==fy) return; sz[fx]+=sz[fy],f[fy]=fx;}struct edge{ int u,v,w;}e[N<<1];struct node{ int k,v,pos,ans;}ask[N];bool cmp1(edge a,edge b){ return a.w>b.w;}bool cmp2(node a,node b){ return a.k>b.k;}bool cmp3(node a,node b){ return a.pos =ask[i].k) merge(e[nxte].u,e[nxte].v),++nxte; ask[i].ans=sz[find(ask[i].v)]-1; }// for(int i=1;i<=n;++i) printf("%d ",sz[i]); sort(ask+1,ask+m+1,cmp3); for(int i=1;i<=m;++i) printf("%d\n",ask[i].ans); return 0;}