易爆物(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. ...
随机推荐
- 使用ucontext组件实现的coroutine代码分析
coroutine一般翻译过来就是协程,类似于线程可以切换,而跟线程是由操作系统调度器来实现切换不一样,协程由用户程序自己调度进行切换.我以前也看过协程相关的内容,但没有自己去实现过.最近搞OpenS ...
- selenium-python问题日记
今天在学习selenium时遇到了两个问题,在这里记录一下: 使用unittest框架组织了测试用例后,拓展一下功能就成了我最想做的事情, 所以决定添加发邮件功能. 使用python自带的smtpli ...
- appium第一个安卓自动化工程
转自:https://university.utest.com/how-to-set-up-your-first-android-automation-project-with-appium/ App ...
- 基于node+koa2+mongodb实现简单的导航管理系统
基于node+koa2+mongodb实现简单的导航管理系统 项目说明 本项目gitbub地址 https://github.com/xuess/nav-admin,喜欢请star 基于node 实现 ...
- Python 003- 小知识汇总(更新中)
#查询key是否存在,可以在使用未知的字典的时候使用 #-*- coding:utf-8 -*- D={'a':1,'c':3,'b':2} for key in sorted(D): print(k ...
- web 前端冷知识
前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前 ...
- 主线程 view
参考https://blog.csdn.net/u011001142/article/details/50912358
- react native 中的redux 理解
redux 中主要分为三大块,分别是Action Reducer 与Store. 1.Action是js的一个普通对象,是store数据的唯一来源.通过store.dispath()讲action传到 ...
- 一步一步学Silverlight 2系列(10):使用用户控件
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- Android 不同阶段 Logo 显示
/********************************************************************* * Android 不同阶段 Logo 显示 * 说明: ...