ural1671 Anansi's Cobweb
Anansi's Cobweb
Memory limit: 64 MB
Input
Output
Samples
input | output |
---|---|
4 4 |
1 2 3 |
3 1 |
3 |
分析:倒着写并查集;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,p[maxn],ans[maxn],query[maxn],coco[maxn];
struct node
{
int x,y;
}a[maxn];
int find(int x)
{
return p[x]==x?x:p[x]=find(p[x]);
}
int main()
{
int i,j;
scanf("%d%d",&n,&m);
rep(i,,n)p[i]=i;
rep(i,,m)scanf("%d%d",&a[i].x,&a[i].y);
scanf("%d",&t);
rep(i,,t)scanf("%d",&query[i]),coco[query[i]]=;
ans[t]=n;
rep(i,,m)
{
if(!coco[i])
{
int fa=find(a[i].x),fb=find(a[i].y);
if(fa!=fb)p[fa]=fb,ans[t]--;
}
}
for(i=t-;i>=;i--)
{
int fa=find(a[query[i+]].x),fb=find(a[query[i+]].y);
if(fa!=fb)p[fa]=fb,ans[i]=ans[i+]-;
else ans[i]=ans[i+];
}
printf("%d",ans[]);
rep(i,,t)printf(" %d",ans[i]);
printf("\n");
//system("pause");
return ;
}
ural1671 Anansi's Cobweb的更多相关文章
- URAL 1671 Anansi's Cobweb (并查集)
题意:给一个无向图.每次查询破坏一条边,每次输出查询后连通图的个数. 思路:并查集.逆向思维,删边变成加边. #include<cstdio> #include<cstring> ...
- 1671. Anansi's Cobweb(并查集)
1671 并查集 对于询问删除边之后的连通块 可以倒着加边 最后再倒序输出 #include <iostream> #include<cstdio> #include<c ...
- ural 1671 Anansi's Cobweb
这道题是并差集的简单应用 #include <cstdio> #include <cstring> #include <algorithm> #define max ...
- Codeforces 833D Red-black Cobweb【树分治】
D. Red-black Cobweb time limit per test:6 seconds memory limit per test:256 megabytes input:standard ...
- 【CF833D】Red-Black Cobweb(点分治)
[CF833D]Red-Black Cobweb(点分治) 题面 CF 有一棵树,每条边有一个颜色(黑白)和一个权值,定义一条路径是好的,当且仅当这条路径上所有边的黑白颜色个数a,b满足2min(a, ...
- 【CF833D】Red-Black Cobweb
[CF833D]Red-Black Cobweb 题面 洛谷 题解 看到这种统计路径的题目当然是淀粉质啦. 考虑转化一下信息设一条路径上有红点\(a\)个,黑点\(b\)个 则\(2min(a,b)\ ...
- CF833D Red-Black Cobweb 点分治、树状数组
传送门 统计所有路径的边权乘积的乘积,不难想到点分治求解. 边权颜色比例在\([\frac{1}{2},2]\)之间,等价于\(2B \geq R , 2R \geq B\)(\(R,B\)表示红色和 ...
- Codeforces 833D Red-Black Cobweb [点分治]
洛谷 Codeforces 思路 看到树上路径的统计,容易想到点分治. 虽然只有一个限制,但这个限制比较麻烦,我们把它拆成两个. 设黑边有\(a\)条,白边有\(b\)条,那么有 \[ 2a\geq ...
- CF833D Red-Black Cobweb
题面 题解 点分治大火题... 设白边数量为$a$,黑边为$b$,则$2min(a,b)\geq max(a,b)$ 即$2a\geq b\;\&\&2b\geq a$ 考虑点分治时如 ...
随机推荐
- away 3d的一些问题
不能成功draw m3u8视频流问题: Texture2DBase.as return context.createRectangleTexture(_width, _height, Context3 ...
- NTP服务器时间同步
CentOS 配置服务器NTP同步 1 查看是否安装 rpm -aq | grep ntp 2 安装 yum -y install ntp 3 配置 /etc/ntp.conf restrict 访问 ...
- eclipse关联源码的方法
1.在项目的libs目录下,新建一个android-support-v4.jar.properties文件 2.打开android-support-v4.jar.properties,编辑. 输入源码 ...
- jquery datatable 参数api
jQuery 的插件 dataTables 是一个优秀的表格插件,提供了针对表格的排序.浏览器分页.服务器分页.筛选.格式化等功能.dataTables 的网站上也提供了大量的演示和详细的文档进行说明 ...
- 校验 MD5 值
Linux 环境下:打开终端,输入命令:"md5sum filename",将结果与网页提供值对比.Windows 环境下:下载 MD5 校验软件并使用.
- c++判断一个字符串是否是数字
bool isNum(const string& str) { bool bRet = false; bool point = false; ) { return bRet; } ]) &am ...
- iOS View 模糊效果(毛玻璃)
iOS View 模糊效果(毛玻璃) 相关资料 http://stackoverflow.com/questions/18404907/using-gpuimage-to-recreate-ios ...
- web项目docker化的两种方法
标题所讲的两种方法其实就是创建docker镜像的两种方法 第一种:启动镜像后进入容器中操作,将需要的软件或者项目移动到容器中,安装或者部署,然后退出即可 第二种:编写dockerfile,将需要的镜像 ...
- Spring Boot 系列教程4-JDBC
JDBC Java Data Base Connectivity,是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成.不管是Hibe ...
- 从市场运营角度谈Uber中国的第一批用户是怎么来的
声明:这篇文章是从http://www.010lm.com/redian/2016/0312/1206875.html转来的,分享给大家. 1)首先告诉用户Uber是做什么的?即培养用户品牌意识. 我 ...