ural 1671 Anansi's Cobweb
这道题是并差集的简单应用
#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的更多相关文章
- URAL 1671 Anansi's Cobweb (并查集)
题意:给一个无向图.每次查询破坏一条边,每次输出查询后连通图的个数. 思路:并查集.逆向思维,删边变成加边. #include<cstdio> #include<cstring> ...
- 1671. Anansi's Cobweb(并查集)
1671 并查集 对于询问删除边之后的连通块 可以倒着加边 最后再倒序输出 #include <iostream> #include<cstdio> #include<c ...
- ural1671 Anansi's Cobweb
Anansi's Cobweb Time limit: 1.0 secondMemory limit: 64 MB Usatiy-Polosatiy XIII decided to destroy A ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- 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 ...
随机推荐
- puppet yum安装配置,简单证书维护
Puppet学习之puppet的安装和配置 一.Puppet简介 Puppet基于ruby语言开发的自动化系统配置工具,可以C/S模式或独立运行,支持对所有UNIX及类UNIX系统的配置管理,最新版本 ...
- powershell利用winform批量执行tsql语句
#加载.net的winform模块 [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $app= ...
- css实现小三角效果
<!DOCTYPE html><html><head><meta charset="UTF-8"> <title>新闻标 ...
- 无锁,线程安全,延迟加载的单例实现(C#)
单例(singleton)是非常常见,也非常有用的设计模式,当然了, 面试中也是经常会被问到的:)在几乎所有的项目中都能看到它的身影.简而言之,单例保证了一个自定义类型在整个程序的生命周期只被创建一次 ...
- [置顶] vb报表的设计
敲机房收费系统,最难的部分应该就是关于报表的部分了.相对于学生信息管理系统,报表是新内容,在vb中添加报表需要添加第三方控件,首先我们要下载水晶报表,下面就向大家展示一下我设计报表的步骤(我用的新版本 ...
- [AngularJS] angular-md-table for Angular material design
Download from npm:https://www.npmjs.com/package/angular-md-table +: Responsive: Has both Mobile view ...
- 在linux后台执行脚本
1. 使用&符号在后台执行命令 你可以在Linux命令或者脚本后面增加&符号,从而使命令或脚本在后台执行,例如:. $ ./my-shell-script.sh & 2. 使用 ...
- C# 在右下角弹出窗口
窗口代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Da ...
- ADSL拨号连接
dotras是一个提供远程访问服务的组件,使用它可以方便的 进行宽带拨号连接 由于不同的系统中dotras调用的底层api可能不同,所以使用时要根据不同的系统使用不同的dotras. dotras目前 ...
- JAVA多态需要注意的一些问题
public class MainTest { static class A { public int i; public void f() { System.out.println("AA ...