zoukankan      html  css  js  c++  java
  • BZOJ 1015 JSOI2008 星球大战 starwar 并检查集合

    标题效果:给定一个无向图。联通谋求块的数目,以及k一个点的破坏后每次;联通,块的数目

    侧面和摧毁的地步全记录,我们可以做相反的。

    需要注意的是该点不能算作破坏联通块

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define M 400400
    using namespace std;
    struct abcd{
    	int to,next;
    }table[M];
    int head[M],tot;
    int n,m,q;
    int fa[M],stack[M],destroy[M],top,now;
    bool destroyed[M];
    int Find(int x)
    {
    	if(!fa[x]||fa[x]==x)
    		return fa[x]=x;
    	return fa[x]=Find(fa[x]);
    }
    inline void Unite(int x,int y)
    {
    	int fx=Find(x);
    	int fy=Find(y);
    	if(fx==fy)
    		return ;
    	--now;
    	fa[fy]=fx;
    }
    inline void Add(int x,int y)
    {
    	table[++tot].to=y;
    	table[tot].next=head[x];
    	head[x]=tot;
    }
    int main()
    {
    	int i,j,x,y;
    	cin>>n>>m;
    	for(i=1;i<=m;i++)
    	{
    		scanf("%d%d",&x,&y);
    		++x;++y;
    		Add(x,y);
    		Add(y,x);
    	}
    	cin>>q;
    	for(i=1;i<=q;i++)
    	{
    		scanf("%d",&destroy[i]);
    		++destroy[i];
    		destroyed[destroy[i]]=1;
    	}
    	now=n-q;
    	for(j=1;j<=n;j++)
    		if(!destroyed[j])
    			for(i=head[j];i;i=table[i].next)
    				if(!destroyed[table[i].to])
    					Unite(j,table[i].to);
    	stack[++top]=now;
    	for(j=q;j;j--)
    	{
    		x=destroy[j];
    		destroyed[x]=0;
    		++now;
    		for(i=head[x];i;i=table[i].next)
    			if(!destroyed[table[i].to])
    				Unite(x,table[i].to);
    		stack[++top]=now;
    	}
    	while(top)
    		printf("%d
    ",stack[top--]);
    }
    


    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    短连接生成
    google 定位 标记 地址解码 逆解码
    Laravel 文件上传
    Laravel
    对接航信开票-在线二维码开票
    win 下 composer 安装
    对接美团外卖开放平台
    IOS 弹框在微信中导致输入框等失焦 偏移问题解决
    微信公众号-高德地图实例
    对接百度地图API 实现地址转经纬度
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4854754.html
Copyright © 2011-2022 走看看