hdu2473
hdu2473
并查集的删除操作
建立虚点,删除它就断掉了它在原图中的所有关系,而成为独立节点,而且它只能被删除一次,而且删除之后还能进行操作,采用映射(虚点)的方法,建立虚点并把删除之后的操作挪到虚点上来。啊,初始化确实有问题,有可能多次删除的,所以要按操作的数量来,比如全部删除等等数据,哭了
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 2000010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int n,m;
char c;
int d[N],id[N];
int x,y;
int cnt;
int tot;
set<int>s;
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} int find(int x){
if(d[x]==x)return x;
return d[x]=find(d[x]);
} int main(){
while(cin>>n>>m&&(n+m)){
For(i,,N)
d[i]=i;
For(i,,n-)
id[i]=i;
cnt=n;
while(m--){
cin>>c;
if(c=='M'){
in(x);in(y);
int t1=find(id[x]);
int t2=find(id[y]);
if(t1!=t2)
d[t1]=t2;
}
if(c=='S'){
in(x);
id[x]=cnt++;
}
}
s.clear();
For(i,,n-)
s.insert(find(id[i]));
cout<<"Case #"<<++tot<<": "<<s.size()<<endl;
}
return ;
}
hdu2473的更多相关文章
- HDU2473 Junk-Mail Filter 并查集
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU2473 题意概括 一堆点. 要你支持合并两组点.分离某组点中的一个,这两种操作. 点数<=100 ...
- HDU2473 Junk-Mail Filter 【可删除的并查集】
HDU2473 Junk-Mail Filter Problem Description Recognizing junk mails is a tough task. The method used ...
- *HDU2473 并查集
Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 支持删除的并查集 hdu2473
题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long long ; int fa[maxn],id,vi ...
- hdu2473 Junk-Mail Filter 并查集+删除节点+路径压缩
Description Recognizing junk mails is a tough task. The method used here consists of two steps: 1) ...
- HDU2473 Junk-Mail Filter - 并查集删除操作(虚父节点)
传送门 题意: 每次合并两份邮件,或者将某一份邮件独立出来,问最后有多少个邮件集合. 分析: 考虑初始化每个节点的祖先为一个虚父节点(i + n),虚父节点指向它自己.这样可以进行正常的合并操作. 而 ...
- HDU-2473 Junk-Mail Filter(并查集的使用)
原题链接:https://vjudge.net/problem/11782/origin Description: Recognizing junk mails is a tough task. Th ...
随机推荐
- Confluence 6 从一个备份中获得文件附件
页面中的文件附件可以从备份中获得而不需要将备份文件导入到 Confluence 中.这个在用户删掉了附件,但是你还是想恢复这个附件的时候就变得非常有用了. 自动备份和手动备份都允许你进行这个操作,但是 ...
- Confluence 6 Oracle 驱动输入你的数据库细节
Confluence 的安装向导将会指导你一步一步的在 Confluence 中配置安装 Oracle 数据库. 使用 JDBC 连接(默认) JDBC 是推荐的连接你的 Confluence 到数据 ...
- linux下安装nginx及初步认识
linux下安装配置nginx nginx:是一个高性能的反向代理服务器正向代理代理的是客户端,反向代理代理的是服务端. 这里以nginx-1.12.2版本为例子 1.首先去官网下载nginx-1.1 ...
- Django知识点汇总
Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...
- ZenMap扫描笔记
1.软件界面如下,ZenMap 扫描工具是kali linu中对WEB渗透扫描的一款工具
- Mesh无线网络的定义与WiFi的区别
Mesh无线网络的定义与WiFi的区别 无线Mesh网络(无线网状网络)也称为「多跳(multi-hop)」网络,它是一种与传统无线网络完全不同的新型无线网络技术.无线网状网是一种基于多跳路由,对等网 ...
- hdu1213并查集
板子题不多说,上代码 #include<iostream> #include<cstdio> #include<cstring> using namespace s ...
- 微信小程序开发 如何退出当前页面
默认是在首页 wx.navigateBack({ delta: -1 }); 详情参考. https://mp.weixin.qq.com/debug/wxadoc/dev/api/u ...
- 论文阅读笔记三十一:YOLO 9000: Better,Faster,Stronger(CVPR2016)
论文源址:https://arxiv.org/abs/1612.08242 代码:https://github.com/longcw/yolo2-pytorch 摘要 本文提出YOLO9000可以检测 ...
- 设置IDEA中的web