URAL1671 Anansi ' s cobweb (offline do + and check set)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.