标签:following inpu its tle make miss point turn bit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 6079 Accepted Submission(s): 2112
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int n,m,cur; int fa[maxn]; vector<pair<int,int> >o; vector<int>res; int find(int s){ return s==fa[s]?s:fa[s]=find(fa[s]); } inline void merge(int s,int t){ int fa_s=find(s); int fa_t=find(t); if(fa_s!=fa_t){ --cur; fa[fa_s]=fa_t; } } int main() { #ifndef ONLINE_JUDGE freopen("1.txt","r",stdin); #endif while(scanf("%d%d",&n,&m)!=EOF) { o.clear(); res.clear(); for (register int i = 0; i < n; ++i)fa[i] = i; for (register int i = 1, u, v; i <= m; ++i) { scanf("%d%d", &u, &v); o.emplace_back(make_pair(u, v)); } cur = n; res.emplace_back(n); for (register int i = o.size() - 1; i > 0; --i) { merge(o[i].first, o[i].second); res.emplace_back(cur); } for (register int i = res.size() - 1; i >= 0; --i) { printf("%d\n", res[i]); } } return 0; }
标签:following inpu its tle make miss point turn bit
原文地址:https://www.cnblogs.com/czy-power/p/11433052.html