【hihoCoder第十四周】无间道之并查集
就是基础的并查集。0代表合并操作,1代表查询操作。一开始以为会卡路径压缩,忐忑的交了一版裸并查集,结果AC了。数据还是很水的。
以后坚持做hiho,当额外的练习啦~
#include <bits/stdc++.h>
using namespace std; map<string, int> Hash;
int Father[]; int getFather (int x) {
if (x != Father[x]) {
return getFather (Father[x]);
}
return x;
} void Union (int p, int q) {
int x = getFather (p);
int y = getFather (q);
if (x != y) {
Father[y] = x;
}
} int main () {
ios :: sync_with_stdio(false);
cin.tie();
int n, a, cnt = ;
string x, y;
cin >> n;
for (int i = ; i < ; ++ i) {
Father[i] = i;
}
while (n --) {
cin >> a >> x >> y;
if (a == ) {
if (!Hash[x]) {
Hash[x] = cnt ++;
}
if (!Hash[y]) {
Hash[y] = cnt ++;
}
Union (Hash[x], Hash[y]);
} else {
if (!Hash[x]) {
Hash[x] = cnt ++;
}
if (!Hash[y]) {
Hash[y] = cnt ++;
}
if (getFather (Hash[x]) == getFather (Hash[y])) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return ;
}
【hihoCoder第十四周】无间道之并查集的更多相关文章
- HihoCoder第十四周:无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息--额,说远了,总之,小Hi和小H ...
- hihocoder 1066 无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...
- [hihoCoder]无间道之并查集
题目大意: #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之, ...
- hiho #1066 : 无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...
- hihoCoder week14 无间道之并查集
并查集的基本使用 #include <bits/stdc++.h> using namespace std; ; int n, fa[N]; int cnt, tot; map<st ...
- C - 无间道之并查集 HihoCoder - 1066
输入 每个测试点(输入文件)有且仅有一组测试数据. 每组测试数据的第1行为一个整数N,表示黑叔叔总共进行的操作次数. 每组测试数据的第2~N+1行,每行分别描述黑叔叔的一次操作,其中第i+1行为一个整 ...
- hihoCoder 1515 分数调查(带权并查集)
http://hihocoder.com/problemset/problem/1515 题意: 思路: 带权并查集的简单题,计算的时候利用向量法则即可. #include<iostream&g ...
- hihoCoder #1291 : Building in Sandbox 逆向处理+并查集维护
/** 题目:#1291 : Building in Sandbox 链接:https://hihocoder.com/problemset/problem/1291 题意:就是一个三维的空间里,按照 ...
- Hiho----无间道之并查集
题目: 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小Ho决定趁着这朗朗春光出去 ...
随机推荐
- C++ 命名规范小结
1. #defines and const test.h #ifndef TEST_H #define TEST_H #endif #define FALSE 0 #define TRUE (!FAL ...
- css(二)
重新排传智的首页!头部和左边的部分完成了! <!doctype html> <html lang="en"> <head> <meta c ...
- PHP发送POST请求的三种方式
class Request{ public static function post($url, $post_data = '', $timeout = 5){//curl $ch = curl_in ...
- AxisFault另外一个问题
出现以下情况,能够是proxy.setEndpoint(endpoint);中endpoint不正确导致 因该是:endpoint = http://127.0.0.1/8080/项目名/servic ...
- CentOS6.7 常用操作命令
centos 安装py环境 1.安装wget工具: yum install wget 2.安装Python-2.7.8: wget --no-check-certificate https://www ...
- 解决SQL Server 占用80端口
停用掉下面的服务就可以了:
- 关于textbox.attributes["value"]的问题
在“修改”时,出现这个问题,后台点击修改时,应该是文本框出现一些初始值 BLL.manager bll = new BLL.manager(); Model.manager model = bll.G ...
- openfire spark 二次 开发 服务插件
==================== 废话 begin ============================ 最近老大让我为研发平台增加即时通讯功能.告诉我用comet 在web端实现即 ...
- RDD 重新分区,排序 repartitionAndSortWithinPartitions
需求:将rdd数据中相同班级的学生分到一个partition中,并根据分数降序排序. 此实例用到的repartitionAndSortWithinPartitions是Spark官网推荐的一个算子,官 ...
- js中substring和substr的用法 (转)
1.substring 方法 定义和用法 substring 方法用于提取字符串中介于两个指定下标之间的字符. 语法 stringObject.substring(start,stop) 参数 ...