这道题是并差集的简单应用

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std; int x[maxn],y[maxn],flag[maxn],f[maxn],t[maxn];
bool vis[maxn]; inline int find(int x)
{
if(x==f[x]) return x;
return f[x]=find(f[x]);
}
int main()
{
int n,m,q;
scanf("%d%d",&n,&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&x[i],&y[i]);
}
scanf("%d",&q);
memset(vis,false,sizeof(vis));
for(int i=; i<=q; i++)
{
scanf("%d",&flag[i]);
vis[flag[i]]=true;
}
for(int i=; i<=n; i++)
f[i]=i;
for(int i=; i<=m; i++)
{
if(!vis[i])
{
int a=find(x[i]);
int b=find(y[i]);
if(a!=b)
f[a]=b;
}
}
int ans=;
for(int i=; i<=n; i++)
{
if(f[i]==i) ans++;
}
for(int i=q; i>; i--)
{
int a=find(x[flag[i]]);
int b=find(y[flag[i]]);
t[i]=ans;
if(a!=b)
{
f[a]=b;
ans--;
}
}
for(int i=; i<=q; i++)
{
if(i==q) printf("%d\n",t[i]);
else printf("%d ",t[i]);
}
return ;
}

ural 1671 Anansi's Cobweb的更多相关文章

  1. URAL 1671 Anansi's Cobweb (并查集)

    题意:给一个无向图.每次查询破坏一条边,每次输出查询后连通图的个数. 思路:并查集.逆向思维,删边变成加边. #include<cstdio> #include<cstring> ...

  2. 1671. Anansi's Cobweb(并查集)

    1671 并查集 对于询问删除边之后的连通块 可以倒着加边 最后再倒序输出 #include <iostream> #include<cstdio> #include<c ...

  3. ural1671 Anansi's Cobweb

    Anansi's Cobweb Time limit: 1.0 secondMemory limit: 64 MB Usatiy-Polosatiy XIII decided to destroy A ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  9. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

随机推荐

  1. 浅析Linux系统下用户与权限管理

    Linux作为一种多用户多任务操作系统,在日常的使用中不可避免地要划分出一个角色的概念来管理和使用计算机,这个角色与每一个计算机使用者关联,在Linux中称这种角色为用户.而在每一个用户使用计算机的过 ...

  2. HDU 2639 Bone Collector II(01背包变型)

    此题就是在01背包问题的基础上求所能获得的第K大的价值. 详细做法是加一维去推当前背包容量第0到K个价值,而这些价值则是由dp[j-w[ i ] ][0到k]和dp[ j ][0到k]得到的,事实上就 ...

  3. win7-64bit 下oracle11g plsql 的正确安装

    本人在PC机上安装了Oracle 11g 版本号的数据库服务,通过PL/SQL连接数据库时总是无法连接,位的oracle客户端工具instantclient进行转换,另外一种plsql的不能安装到文件 ...

  4. Ellipse常用快捷键

    Ctrl+m:视窗大小变化 Ctrl+F6:在打开的文件件进行切换 Ctrl+F7:在资源窗口间切换Ctrl+F8:在各种模式下进行切换 Ctrl+e:选择某个打开的文件Shift+home:整行选取 ...

  5. C# string.Format谨慎使用

    string.Format string.Format在处理文本的时候很有用处,但是在使用占位符的时候一定要注意内容中的特殊字符{}. 示例 string.Format("你好{0},这是{ ...

  6. java byte数组与int,long,short,byte转换

    public class DataTypeChangeHelper { /** * 将一个单字节的byte转换成32位的int * * @param b * byte * @return conver ...

  7. ·数据库基本内容回顾-day16.06.30

    一. 模式的定义和删除  ---创建了一个模式,就创建了一个数据库命名空间,一个框架.cascade.restrict create schema<模式名> authorization & ...

  8. machine learning in action , part 1

    We should think in below four questions: the decription of machine learning key tasks in machine lea ...

  9. ASP.NET-FineUI开发实践-1

    用.Net开发3年,主要接触资产管理,生产流程,质量追溯,.Net在这方面还是很靠谱的.2月低接触FineUI,那时版本是3.0+,第一眼让我想起了ExtJs,其实就是用.Net封装了ExtJs让AS ...

  10. VS2015编译器问题简单记录

    问题:VS2015community 无法查找或打开 pdb 文件 解决办法: 1.点击工具->选项, 在选项窗口中展开左侧菜单: 2.展开调试->常规,然后在右边的窗格中勾选“启用服务器 ...