Portal
The main idea: to give an undirected graph, delete the Q-bar, every time you delete the number of connected blocks is queried once.
Idea: Off-line, the cut edge conversion to add edge, every addition to the edge, if two vertices are not connected to use and check set to merge the two connected blocks.
Code:
#include <cstdio>#include <cstring>#include <algorithm>#define MAXN 100005using namespace STD;intN, M, q;intS[MAXN], T[MAXN];intBAN[MAXN], FA[MAXN], ST[MAXN];BOOLF[MAXN], G[MAXN];intRtintu) {if(Fa[u]! = u)returnFA[U] = RT (Fa[u]);returnU;}intMain () { while(~scanf("%d%d", &n, &m)) {memset(Ban,0,sizeofBAN);memset(FA,0,sizeofFA);memset(St,0,sizeofST);memset(F,0,sizeoff);memset(g,0,sizeofg); for(inti =1; I <= m; i + +)scanf("%d%d", &s[i], &t[i]); for(inti =1; I <= N; i + +) fa[i] = i;scanf("%d", &q); for(inti =1; I <= Q; i + +) {scanf("%d", Ban + i); F[ban[i]] =1; }intans = n; for(inti =1; I <= m; i + +)if(!f[i]) {intT1 = RT (S[i]), t2 = RT (T[i]);if(T1! = t2) Fa[t1] = t2, ans--; } for(inti = q; i >0; I--) {st[i] = ans;intT1 = RT (S[ban[i]), t2 = RT (T[ban[i]]);if(T1! = t2) Fa[t1] = t2, ans--; }printf("%d", st[1]); for(inti =2; I <= Q; i + +)printf("%d", St[i]);Putchar(' \ n '); }return 0;}
Copyright NOTICE: Please feel free to reprint O (∩_∩) o
URAL1671 Anansi ' s cobweb (offline do + and check set)