1 条题解
- 
  0
#include<bits/stdc++.h> #include<algorithm> using namespace std; typedef unsigned long long ull; typedef long long ll; priority_queue<int> q;//big根堆,数字越大,优先级越高 int f[100005],size[100005],n,m,x,y; int find(int x) { if(f[x]==x) return x; else return f[x]=find(f[x]); } void merge(int x,int y) { int fx=find(x); //x的祖先 int fy=find(y); //y的祖先 if(fx==fy) return ; //本就在一个集合 if(size[fx]<size[fy]) { f[fx]=fy; //将x的祖先设为y size[fy]+=size[fx]; //连通分量小的合并到大 } else { f[fy]=fx; size[fx]+=size[fy]; } } int main() { cin>>n>>m; for(int i=1;i<=n;i++) { f[i]=i;//自己是自己的祖先 size[i]=1; } for(int i=1;i<=m;i++) { cin>>x>>y; merge(x,y); q.push(size[find(x)]); cout<<q.top()<<"\n"; } return 0; } 
- 1
 
信息
- ID
 - 3152
 - 时间
 - 1000ms
 - 内存
 - 256MiB
 - 难度
 - 5
 - 标签
 - (无)
 - 递交数
 - 5
 - 已通过
 - 5
 - 上传者