【题意分析】

  给你一张无向图,要求支持删点和询问连通块数。

【解题思路】

  可以直接可持久化并查集大力艹过去。

  考虑到正着删点就是倒着加点,所以并不需要可持久化。复杂度O((k+m)α(n))。

【参考代码】

  当时还在玩泥巴,实现有点naive,常数奇大无比。。

 #include<cstdio>
#include<cstring>
#include<set>
#define REP(I,start,end) for(int I=start;I<=end;I++)
#define PER(I,start,end) for(int I=start;I>=end;I--)
using namespace std;
set<int> tree;
int n,m,k,edge=,q[],father[],head[],next[],point[],sav[];
bool destroyed[];
inline void addEdge(int from,int to)
{
next[++edge]=head[from];
head[from]=edge;
point[edge]=to;
}
inline int getFa(int n)
{
if(father[n]==n)
return n;
return father[n]=getFa(father[n]);
}
int main()
{
scanf("%d%d",&n,&m);
REP(i,,m)
{
int u,v;
scanf("%d%d",&u,&v);
addEdge(u,v);
addEdge(v,u);
}
scanf("%d",&k);
memset(destroyed,,sizeof(destroyed));
REP(i,,k)
{
scanf("%d",q+i);
destroyed[q[i]]=true;
}
REP(i,,n-)
father[i]=i;
REP(i,,n-)
if(!destroyed[i])
{
int t=head[i];
while(t)
{
int p=point[t];
if(!destroyed[p])
father[getFa(p)]=getFa(i);
t=next[t];
}
}
tree.clear();
REP(i,,n-)
{
int fa=getFa(i);
if(!destroyed[i]&&tree.find(fa)==tree.end())
tree.insert(fa);
}
sav[k]=tree.size();
PER(i,k-,)
{
int P=q[i+],t=head[P];
destroyed[P]=false;
tree.clear();
while(t)
{
int p=point[t];
if(!destroyed[p])
{
int fa2=getFa(p);
tree.insert(fa2);
father[getFa(P)]=fa2;
}
t=next[t];
}
sav[i]=sav[i+]-tree.size()+;
}
REP(i,,k)
printf("%d\n",sav[i]);
return ;
}

bzoj1015题解的更多相关文章

  1. BZOJ1015[JSOI2008]星球大战starwar题解报告

    题目链接 考虑正序去除点去掉其所有连边十分复杂,可以倒序离线处理,每次新建一个点,连接其连边,用并查集统计联通块的个数. 附代码 #include<iostream> #include&l ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. 微信小程序 滚动到底部

    1.html <view id="bottom"></view> 2. onReady: function () { //滚动到底部 let query = ...

  2. 配置文件--spring cloud Config

    配置中心--Spring cloud Config 通过本次学习,我们应该掌握: Config Server 读取配置文 Config Server 从远程 Git 仓库读取配置文 搭建芮可用 Con ...

  3. mysql5.7问题:[Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool

    在关闭mysql5.7的时候发现问题,一直处于夯住状态 [root@localhost ~]# /etc/init.d/mysqld stop Shutting down MySQL......... ...

  4. Hadoop(二)HDFS

    海量数据处理 分而治之 核心思想: 把数据分发到多个节点 移动计算到数据附近 计算节点进行本地数据处理 优选顺序,次之随机读 一.HDFS概述 修改,先删除,再重新生成 1.架构 namenode维护 ...

  5. 建模+线性dp——cf1201D

    这类题目要首先把模型建立起来,挑选一个好的状态能让dp方程简化很多 /* dp[i][0]表示从右到左,最后停在左端 dp[i][1]表示从左到右,最后停在右端 dp[i+1][0]=min(dis( ...

  6. spring之循环依赖问题如何解决

    首先,spring是支持循环依赖的.但是循环依赖并不好. 最近,我在使用jenkins自动化部署,测试打出来的jar包,出现了循环依赖的问题. 在这里说一下,我解决问题的过程 我首先根据提示找到循环依 ...

  7. 自己写的一些Delphi常用函数

    今天在整理以前写过的代码,发现有些函数还是挺实用的,决定将其贴到Blog上,与众多好友一起分享.{*************************************************** ...

  8. tp U函数 logs

    注意 U 函数 项目今天已经搞定了本以为可以上线了没问题了,但是 当我把tp调试模式关闭后:      define('APP_DEBUG',false); 页面完全加载不出来,于是开启:  'SHO ...

  9. C++——代码风格

    google代码风格 1.使用安全的分配器(allocator),如scoped_ptr,scoped_array 2.测试用的,其他的不能用: 2.1 友元 2.2 C++异常 2.3 RTTI 3 ...

  10. 2019杭电多校第三场hdu6609 Find the answer(线段树)

    Find the answer 题目传送门 解题思路 要想变0的个数最少,显然是优先把大的变成0.所以离散化,建立一颗权值线段树,维护区间和与区间元素数量,假设至少减去k才能满足条件,查询大于等于k的 ...