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的更多相关文章

  1. HDU2473 Junk-Mail Filter 并查集

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU2473 题意概括 一堆点. 要你支持合并两组点.分离某组点中的一个,这两种操作. 点数<=100 ...

  2. HDU2473 Junk-Mail Filter 【可删除的并查集】

    HDU2473 Junk-Mail Filter Problem Description Recognizing junk mails is a tough task. The method used ...

  3. *HDU2473 并查集

    Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. 支持删除的并查集 hdu2473

    题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long long ; int fa[maxn],id,vi ...

  5. hdu2473 Junk-Mail Filter 并查集+删除节点+路径压缩

    Description Recognizing junk mails is a tough task. The method used here consists of two steps:  1) ...

  6. HDU2473 Junk-Mail Filter - 并查集删除操作(虚父节点)

    传送门 题意: 每次合并两份邮件,或者将某一份邮件独立出来,问最后有多少个邮件集合. 分析: 考虑初始化每个节点的祖先为一个虚父节点(i + n),虚父节点指向它自己.这样可以进行正常的合并操作. 而 ...

  7. HDU-2473 Junk-Mail Filter(并查集的使用)

    原题链接:https://vjudge.net/problem/11782/origin Description: Recognizing junk mails is a tough task. Th ...

随机推荐

  1. Confluence 6 SQL Server 创建一个数据库和数据库用户

    一旦你成功安装了 SQL Server 服务器,请按照下面的方法为你的 Confluence 创建数据库用户和数据库: 使用你的 SQL 管理员权限,创建一个新的数据库(例如 confluence). ...

  2. Confluence 6 影响语言的其他设置

    一个独立的用户可以在 Confluence 中选择应用到界面文字和消息中的语言.请注意,支持的语言类型基于在 Confluence 中安装的语言包. 你登录使用 Confluence 回话的语言基于下 ...

  3. jquery_ajax 跨域

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. mongo数据库的各种查询语句示例

    左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * from users db.users.find({"age" ...

  5. SpringData使用与整合

    SpringData 整合源码:链接: https://pan.baidu.com/s/1_dDEEJoqaBTfXs2ZWsvKvA 提取码: cp6s(jar包自行寻找) author:Simpl ...

  6. 三.NFS存储服务

    01. 课程回顾 备份服务概念介绍(rsync备份服务利用相应算法,实现增量数据同步) 备份服务工作方式说明: 1. 本地数据备份同步方式(类似cp命令) 2. 远程数据备份同步方式(类似scp命令) ...

  7. LeetCode(108):将有序数组转换为二叉搜索树

    Easy! 题目描述: 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组 ...

  8. 批量杀掉多个pid文件中记录的pid进程, 并集成到shell脚本中

    head_files=`find ./fmsConf/ -name "*.pid"` for file in $head_files do cat $file | awk rm - ...

  9. delete web server(nginx)

    #!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" #conf_dir2="/usr/local/apache2/ ...

  10. 滴水穿石-08IO

    1.0 File a:构造方法 package d8; import java.io.File; public class FileGouZao { public static void main(S ...