标签:
#include<cstdio> #include<iostream> #include<string.h> #include<stack> #define maxn 10005 using namespace std; int pre[maxn]; int num; void init() { for(int i=0;i<maxn;i++) pre[i]=i; } int find(int x) { if(pre[x]==x) return x; else return pre[x]=find(pre[x]); } void merge(int x,int y) { x=find(x); y=find(y); if(x!=y) { num--; pre[y]=x; } } int main() { cin.sync_with_stdio(false); int n,m; while(cin>>n>>m) { stack<int> fuck,fuck2; int ret[m]; while(m--) { int x,y; cin>>x>>y; fuck.push(x),fuck.push(y); } init(); num=n; int rett=0; while(!fuck.empty()) { int yy=fuck.top(); fuck.pop(); int xx=fuck.top(); fuck.pop(); ret[rett++]=num; merge(xx,yy); } for(int i=rett-1;i>=0;i--) cout<<ret[i]<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/z1141000271/p/5791194.html