Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Zhandos Kapezov
- #include <iostream>
- #include <math.h>
- #include <cmath>
- #include <vector>
- #include <utility>
- #include <algorithm>
- #include <cstdio>
- #include <cstdlib>
- #include <fstream>
- #include <string>
- #include <string.h>
- #include <sstream>
- #include <map>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <limits>
- #include <list>
- #include <functional>
- #include <bitset>
- #include <numeric>
- #include <iomanip>
- #include <ctime>
- #include <ctype.h>
- using namespace std;
- typedef long long ll;
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- #define sz size()
- #define sqr(x) ((x)*(x))
- #define INF numeric_limits<int>::max()
- const int maxn=100000;
- const int maxm=100000;
- int p[maxn+10];
- int get(int v) {
- if (v==p[v]) return v;
- p[v]=get(p[v]);
- return p[v];
- }
- void unite(int a, int b) {
- if (rand()&1)
- p[a]=b; else
- p[b]=a;
- }
- int x[maxm+10], y[maxm+10], u[maxm+10], q[maxm+10];
- int n, m, a, b, all, k;
- vector<int> res;
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","rt",stdin);
- freopen("output.txt","wt",stdout);
- #endif
- cin>>n>>m;
- for (int i=0; i<m; i++) scanf("%d%d", x+i, y+i);
- cin>>k;
- memset(u, 0, sizeof(u));
- for (int i=0; i<k; i++) scanf("%d", q+i), q[i]--, u[q[i]]=1;
- for (int i=1; i<=n; i++) p[i]=i;
- for (int i=0; i<m; i++)
- if (!u[i]) {
- // cerr<<x[i]<<" "<<y[i]<<endl;
- a=get(x[i]); b=get(y[i]);
- if (a!=b) unite(a, b);
- }
- memset(u, 0, sizeof(u));
- all=0;
- for (int i=1; i<=n; i++) {
- p[i]=get(p[i]);
- if (!u[p[i]]) all++;
- u[p[i]]=1;
- }
- // for (int i=1; i<=n; i++) cerr<<p[i]<<" ";
- res.pb(all);
- for (int i=k-1; i>0; i--) {
- a=get(x[q[i]]); b=get(y[q[i]]);
- if (a!=b) {
- all--;
- unite(a, b);
- }
- res.pb(all);
- }
- reverse(res.begin(), res.end());
- for (int i=0; i<res.sz; i++) printf("%d ", res[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement