易爆物(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. ...
随机推荐
- DBExecutor android 数据库框架
https://github.com/eltld/DBExecutor android 数据库框架,sqlite database
- CycleViewPager
https://github.com/zhaozhentao/CycleViewPager
- android keyEvent
http://developer.android.com/reference/android/view/KeyEvent.html
- wxpython中控件对键盘输入无响应的可能原因
问题描述: 开发环境:Win7 32bit + Python2.7.6 + WxPython 3.0.1-b20140707 开发某初级CAD软件中,需要实现点击TreeCtrl控件的相应选择,实现G ...
- Spring Boot 动态数据源(多数据源自己主动切换)
本文实现案例场景: 某系统除了须要从自己的主要数据库上读取和管理数据外.另一部分业务涉及到其它多个数据库,要求能够在不论什么方法上能够灵活指定详细要操作的数据库. 为了在开发中以最简单的方法使用,本文 ...
- 织梦dedecms中修改标题与简略标题长度的方法
本文介绍了dedecms中修改标题与简略标题长度的方法,进入dedecms后台,系统——系统基本参数——其他选项——文档标题最大长度——在这修改为200或更大. 一.修改标题 进入dedecms后台, ...
- eclipse本地覆盖版本库
1,右键team,与资源库同步 2,选中冲突文件,右键“更新”,此时本地代码出现冲突 3,选中冲突文件,右键点击“标记为解决”,勾选第二项,以本地版本为准 4,冲突被解决,正常提交本地代码
- 动态的添加ImageView到LinearLayout中并居中显示
ImageView imageView = new ImageView(mActivity); imageView.setImageResource(R.mipmap.gengduo); Linear ...
- codeforces 437A. The Child and Homework 解题报告
题目链接:http://codeforces.com/problemset/problem/437/A 题目意思:给出四个选项A.B.C.D选项的内容描述,要求选出符合以下条件的一项. (1)如果某个 ...
- hadoop异常:Be Replicated to 0 nodes, instead of 1
Hadoop 坑爹的Be Replicated to 0 nodes, instead of 1 异常 博客分类: Java 编程 HadoopITeyeJSP算法Apache 有段时间不写博客了, ...