正着显然不可做,我们采取反向并查集,将删点改为加点,每次贪心的认为加了一个联通块,一旦不符就减一。

 #include<bits/stdc++.h>
using namespace std;
const int N=4e6+;
bool del[N],v[N];
int f[N],p[N],head[N],cnt,tot,ans[N],n,m,k;
int get(int x){return x==f[x]?x:f[x]=get(f[x]);}
struct node{
int to,nex;
}e[N];
void addd(int x,int y){e[++cnt].to=y;e[cnt].nex=head[x];head[x]=cnt;}
void add(int x)
{
int fx=get(x);
for(int i=head[x];i;i=e[i].nex)
{
int y=e[i].to;
if(v[y])
{
int fy=get(y);
if(fy!=fx)f[fy]=fx,tot--;
}
}
}
int main()
{
scanf("%d%d",&n,&m);int x,y;
for(int i=;i<=n;++i)f[i]=i;
for(int i=;i<=m;++i)
{
scanf("%d%d",&x,&y);
addd(x,y);addd(y,x);
}
scanf("%d",&k);
for(int i=;i<=k;++i)
{
scanf("%d",&p[i]);
del[p[i]]=;
}
for(int i=;i<n;++i)
{
if(!del[i])
{
tot++;
add(i);
v[i]=;
}
}
ans[]=tot;
for(int i=k;i;--i)
{
tot++;
add(p[i]);
v[p[i]]=;
ans[k-i+]=tot;
}
for(int i=k;i>=;--i)printf("%d\n",ans[i]);
return ;
}

BZOJ [JSOI2008]星球大战starwar的更多相关文章

  1. BZOJ 1015: [JSOI2008]星球大战starwar 并查集

    1015: [JSOI2008]星球大战starwar Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝 ...

  2. 【BZOJ】1015: [JSOI2008]星球大战starwar

    1015: [JSOI2008]星球大战starwar 题意:一个点数为N(1<= 40w),边数为M(1<=20w)的图,总共删除k个节点,问开始以及每次删除一个节点之后图的连通块数? ...

  3. BZOJ 1015 [JSOI2008]星球大战starwar

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 3551  Solved: 1581[Submit ...

  4. BZOJ 1015:[JSOI2008]星球大战starwar(逆向处理+并查集)

    [JSOI2008]星球大战starwar                                                时间限制: 3 Sec 内存限制: 162 MB[题目描述] ...

  5. 1015: [JSOI2008]星球大战starwar

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec Memory Limit: 162 MB Description 很久以前,在一个遥远的星系,一个黑暗的帝国 ...

  6. BZOJ1015[JSOI2008]星球大战starwar[并查集]

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 5253  Solved: 2395[Submit ...

  7. [1015][JSOI2008]星球大战starwar(并查集)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 2124  Solved: 909[Submit] ...

  8. bzoj1015:1015: [JSOI2008]星球大战starwar

    应该是全部读入之后再添加边用并查集就可以了. yyl用空间换时间.u[]v[]等将边预存起来. #include<cstdio> #include<cstring> #incl ...

  9. BZOJ1015 [JSOI2008]星球大战starwar(并查集)

    1015: [JSOI2008]星球大战starwar Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 3895  Solved: 1750[Submit ...

随机推荐

  1. 绝妙的SQL行列转换语句

      说明:普通行列转换(version 1.0)仅针对sql server 2000提供静态和动态写法,version 2.0增加sql server 2005的有关写法. 问题:假设有张学生成绩表( ...

  2. HDU 2516 取石子游戏 (找规律)

    题目链接 Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍.取完者胜.先取者负输出" ...

  3. VC拷贝字符串到剪切板

    ] ="中华人民共和国"; DWORD dwLength = ; // 要复制的字串长度 HANDLE hGlobalMemory = GlobalAlloc(GHND, dwLe ...

  4. password passphrase passcode 的区别

    In general, passphrases are long passwords and passcodes are numeric-only passwords.

  5. 35 - 并发编程-GIL-多进程

    目录 1 GIL 1.1 为什么会有GIL 1.2 GIL与thread lock 1.3 个人总结 2 multiprocessing模块 2.1 Process类 2.2 Process类的方法 ...

  6. Python异常捕捉try except else finally有return时执行顺序探究

    转载自 https://www.cnblogs.com/JohnABC/p/4065437.html 学习python或者其他有异常控制的编程语 言, 大家很有可能说try except finall ...

  7. Redis 启动警告解决【转】

    [root@centos224]# service redisd start :M Nov :: (it was originally set to ). _._ _.-``__ ''-._ _.-` ...

  8. WPF之模拟打开或关闭Windows功能

    用WPF模拟打开或关闭Windows功能的实现方法其实很简单,主要用递归判断当前节点的子节点和父节点的选中状态就行了. 一.效果演示 先看看效果图: 二.部分代码 xaml代码: <TreeVi ...

  9. Django自定义UserModel并实现认证和登录

    自定义UserModel 环境:django 1.9.11+python 2.7 from django.contrib.auth.models import AbstractUser class U ...

  10. 千万不要运行的 Linux 命令

    本文中列出的命令绝对不可以运行,即使你觉得很好奇也不行,除非你是在虚拟机上运行(出现问题你可以还原),因为它们会实实在在的破坏你的系统.所以不在root等高级管理权限下执行命令是很好的习惯. 本文的目 ...