易爆物(X-Plosives )基础并查集
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = + ;
int fa[maxn]; int Find(int x){
if (x == fa[x])
return x;
else
return fa[x] = Find(fa[x]);
} int main(){
int a, b;
while (cin >> a){ //init
for (int i = ; i < maxn; i++)
fa[i] = i;
int ans = ;
while (a != -){
cin >> b;
a = Find(a);
b = Find(b);
if (a == b)
ans++;
else
fa[b] = a;
cin >> a;
}
cout << ans << endl;
}
//system("pause");
return ;
}
易爆物(X-Plosives )基础并查集的更多相关文章
- hdu 1829 基础并查集,查同性恋
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- HDU4496 D-City【基础并查集】
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to ...
- AOJ 2170 Marked Ancestor (基础并查集)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=45522 给定一棵树的n个节点,每个节点标号在1到n之间,1是树的根节点,有如 ...
- poj2236 基础并查集
题目链接:http://poj.org/problem?id=2236 题目大意:城市网络由n台电脑组成,因地震全部瘫痪,现在进行修复,规定距离小于等于d的电脑修复之后是可以直接相连 进行若干操作,O ...
- 基础并查集poj2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- CodeForces - 827A:String Reconstruction (基础并查集)
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- hdu1325 Is It A Tree? 基础并查集
#include <stdio.h> #include <string.h> ], g[]; int find(int x) //并查集的查找,找到共同的父亲 { if (f[ ...
- HDU1213How Many Tables(基础并查集)
HDU1213How Many Tables Problem Description Today is Ignatius' birthday. He invites a lot of friends. ...
随机推荐
- Vue 建立工程
npm install -g vue npm install -g vue-cli vue init webpack my-project cd my-project npm isntall npm ...
- find the longest of the shortest (hdu 1595 SPFA+枚举)
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Material Design (四),AppBarLayout的使用
前言 AppBarLayout,顾名知意.就是用来给AppBar布局的容器,是LinearLayout的子类.而AppBar就包括我们通常所知道的ActionBar,Toolbar. AppBarL ...
- BIOS维修技术
BIOS是电脑中最基础且最重要的程序,为电脑提供最低级且最直接的硬件控制,电脑的原始操作都是依照固化在BIOS里的程序来完成的.因此如果BIOS出现故障将会导致影响电脑的正常工作.BIOS故障有很多, ...
- linux 文件记录锁详解
一: linux记录锁更恰当的称呼应该是范围锁,它是对文件某个范围的锁定. 关于记录锁的功能就是fcntl提供的第五个功能,具体使用如下: int fcntl(int fd, int cmd, str ...
- ITOO高校云平台之考评系统项目总结
高校云平台,将云的概念引入到我的生活, 高校云平台主要是以各大高校的业务为基础设计开发,包含权限系统,基础系统.新生入学系统.考评系统,成绩系统.选课系统,视频课系统.3月份參加云平台3.0的开发,至 ...
- Educational Codeforces Round 9 E. Thief in a Shop NTT
E. Thief in a Shop A thief made his way to a shop. As usual he has his lucky knapsack with him. Th ...
- 3531: [Sdoi2014]旅行
3531: [Sdoi2014]旅行 Time Limit: 20 Sec Memory Limit: 512 MB Submit: 1731 Solved: 772 [Submit][Statu ...
- LOJ#139. 树链剖分
LOJ#139. 树链剖分 题目描述 这是一道模板题. 给定一棵$n$个节点的树,初始时该树的根为 1 号节点,每个节点有一个给定的权值.下面依次进行 m 个操作,操作分为如下五种类型: 换根:将一个 ...
- HDOJ 5045 Contest
状压DP.. . . Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...