HDU 2473 Junk-Mail Filter 删点并查集
来源:互联网 发布:网络策略 编辑:程序博客网 时间:2024/06/10 02:55
删点并查集,就是用一个新的点标代替之前的点标即可。。 y一下就可以了
#include <cstdio>#include <iostream>#include <algorithm>#include <string.h>#include <vector>#include <map>#include <queue>#include <math.h>#include <string>#include <set>using namespace std;#define mod 1000000007#define ll int#define N 100101ll r[1100010], f[1100010], a[N], top;ll n, m;ll find(ll x){return x==f[x]?x:f[x] = find(f[x]);}void Union(ll x, ll y){ ll fx = find(x), fy = find(y); if(fx==fy) return; if(r[fx]>r[fy]) swap(fx,fy); f[fx] = fy; r[fy] += r[fx];}void Del(ll x){find(a[x]);a[x] = top;r[top] = 1;f[top] = top;top++;}void init(){ for(ll i = 0; i < n; i++) f[i] = a[i] = i, r[i] = 1;top = n;}set<int>s;int main(){int i, j, u, v, Cas = 1;while(scanf("%d %d",&n,&m), n+m){init();while(m--){char c[10]; scanf("%s %d",c,&u);if(c[0]=='M'){scanf("%d",&v);Union(a[u], a[v]);}else Del(u);}s.clear();for(i = 0; i < n; i++) for(i = 0; i < n; i++)s.insert(find(a[i]));printf("Case #%d: %d\n", Cas++, s.size());}return 0;}
0 0
- HDU 2473 Junk-Mail Filter 删点并查集
- HDU 2473 Junk-Mail Filter 删点并查集
- HDU 2473Junk-Mail Filter 【并查集,删点】
- HDU 2473 Junk-Mail Filter 并查集 删点
- hdu 2473 Junk-Mail Filter 并查集 删除点
- HDU 2473 Junk-Mail Filter (删点并查集)
- Junk-Mail Filter(hdu2473并查集+删点操作)
- hdu2473 Junk-Mail Filter(删点并查集)
- HDU 2473 Junk-Mail Filter 并查集拆分
- HDU-2473 Junk-Mail Filter 并查集的删除
- Hdu 2473 Junk-Mail Filter (并查集的删除)
- hdu 2473 Junk-Mail Filter(并查集)
- hdu 2473 Junk-Mail Filter 并查集删除
- hdu 2473 Junk-Mail Filter 并查集
- hdu 2473 Junk-Mail Filter (并查集的删除)
- 并查集 Junk-Mail Filter hdu 2473
- HDU 2473 Junk-Mail Filter 并查集 惰性删除
- hdu 2473 Junk-Mail Filter 并查集删除
- 【Visual C++】游戏开发四十八 浅墨DirectX教程十六 三维地形系统的实现
- Direct2D随笔1——构建D2D环境
- SQL Server 2000 数据库日志太大!如何管理,清除,变小,压缩它
- Objective-C -深浅复制
- 环境变量Path的诡异问题
- HDU 2473 Junk-Mail Filter 删点并查集
- 【Visual C++】游戏开发四十九 浅墨DirectX教程十七 三维天空的实现
- 【Visual C++】游戏开发五十 浅墨DirectX教程十八 雪花飞扬:实现唯美的粒子系统
- 【Visual C++】游戏开发五十一 浅墨DirectX教程十九 网格模型进阶之路
- cocos2d-x3.2-HelloWorld在Android真机测试运行
- Regular Polygon - UVa 10824 几何暴力
- 【Visual C++】游戏开发五十二 浅墨DirectX教程二十 骨骼动画来袭(一)
- Poj 1094 拓扑排序
- 面向对象设计六大原则