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 查看一个任务的执行历史

    希望查看一个计划任务最后运行的时间和这个计划任务最后一次运行花费了多长时间.单击计划任务边上的 历史(History )连接. 如果一个计划任务从来没有运行的胡啊,那么这个历史的链接是不会显示的. 屏 ...

  2. Swift Write to file 到电脑桌面

    (arr as NSArray).write(toFile: "Users/你的用户名/Desktop/mian.plist", atomically: true)

  3. Flask框架(一)

    Flask框架 Flask本身想当于一个内核,其自身几乎所有功能都依靠扩展(邮件扩展Flask-Mail.用户认证Flask-Login),都需要用第三方的扩展来实现.其WSGI工具箱采用Werkze ...

  4. LeetCode(66): 加一

    Easy! 题目描述: 给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会 ...

  5. jvm(转)

    原:https://blog.csdn.net/luomingkui1109/article/details/72820232 1.JVM简析:      作为一名Java使用者,掌握JVM的体系结构 ...

  6. 【C++ Primer | 15】访问控制与继承、继承中的类作用域

    1. 只有D继承B的方式是public时,用户代码才能使用派生类向基类的转换:如果D继承B的方式是受保护的或者私有的,则用户代码不能使用该转换. 2. 不论D以什么方式继承B,D的成员函数和友员函数都 ...

  7. 647. Palindromic Substrings

    Given a string, your task is to count how many palindromic substrings in this string. The substrings ...

  8. Top 查看某些或者某个进程(top -p pid)

    https://blog.csdn.net/zhangfn2011/article/details/7488746?utm_source=blogxgwz5

  9. CentOS命令行向OSS上传文件或文件夹

    下载地址:https://helpcdn.aliyun.com/document_detail/50452.html?spm=a2c4g.11186623.4.2.KyQak3 百度云盘:https: ...

  10. jquery源码中noConflict(防止$和jQuery的命名冲突)的实现原理

    jquery源码中noConflict(防止$和jQuery的命名冲突)的实现原理 最近在看jquery源码分析的视频教学,希望将视频中学到的知识用博客记录下来,更希望对有同样对jquery源码有困惑 ...