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$ 考虑点分治时如 ...
随机推荐
- subversion SVN global ignore pattern
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store */bin */ ...
- Xcode6无法用xib得问题解决方法
1.创建一个新工程,选择singleView application 2.将storyboard和launchscreen删除,选择moveToTrash 3.删除info.plist文件中Main ...
- Oracle10 多行和并
SELECT fspc, wmsys.wm_concat (jsrzmc) as jsr FROM dxjsrxx GROUP BY fspc select fspc, LISTAGG(jsrzmc, ...
- nm applet disable
http://support.qacafe.com/knowledge-base/how-do-i-prevent-network-manager-from-controlling-an-interf ...
- JAVA-面向对象2--继承
1. 继承的好处: 1.提高代码复用性. 2.让类与类之间产生关系,为面向对象的第三大特征 多态 提供了前提 2.java中支持单继承,不直接支持多继承,但对c++中多继承进行了改良.java通过多实 ...
- 3d 人物残像
前言: gameunity 框架 还在继续完善中,0.2版本将会是一次 重大的里程碑. 正文: 哈哈,大家一定流汗了吧.请原谅我为自己代言. 好了,今天我要讲的是 3d人物残像. 首先我来说下 目前 ...
- monkeyrunner对比屏幕局部图像.getSubImage()
monkeyrunner对比屏幕局部图像.getSubImage() monkeyrunner执行测试时使用.takeSnapshot()截图,默认截取整个屏幕,包含了系统的状态栏.真实手机状态栏中包 ...
- MaterialEditText 控件学习
这个视图原始框架地址:https://github.com/rengwuxian/MaterialEditText 指导手册:http://www.rengwuxian.com/post/materi ...
- gnome配置
1.gome-tweak-tool gnome调校工具 2.gnome-shell插件(在gome-tweak-tool中) 可在https://extensions.gnome.org/中下载 ...
- PADS 导Gerber文件
PCB也画了好几年,投板时都是直接发PCB文件,突然间客户让我导出Gerber文件, 一时半会还挺棘手的,上网不停的搜啊搜啊,虽然最终还是搞定了,但耽误了不少时间. 现总结下,把所有相关设置一步一步的 ...