就是基础的并查集。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第十四周】无间道之并查集的更多相关文章

  1. HihoCoder第十四周:无间道之并查集

    #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息--额,说远了,总之,小Hi和小H ...

  2. hihocoder 1066 无间道之并查集

    #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...

  3. [hihoCoder]无间道之并查集

    题目大意: #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之, ...

  4. hiho #1066 : 无间道之并查集

    #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...

  5. hihoCoder week14 无间道之并查集

    并查集的基本使用 #include <bits/stdc++.h> using namespace std; ; int n, fa[N]; int cnt, tot; map<st ...

  6. C - 无间道之并查集 HihoCoder - 1066

    输入 每个测试点(输入文件)有且仅有一组测试数据. 每组测试数据的第1行为一个整数N,表示黑叔叔总共进行的操作次数. 每组测试数据的第2~N+1行,每行分别描述黑叔叔的一次操作,其中第i+1行为一个整 ...

  7. hihoCoder 1515 分数调查(带权并查集)

    http://hihocoder.com/problemset/problem/1515 题意: 思路: 带权并查集的简单题,计算的时候利用向量法则即可. #include<iostream&g ...

  8. hihoCoder #1291 : Building in Sandbox 逆向处理+并查集维护

    /** 题目:#1291 : Building in Sandbox 链接:https://hihocoder.com/problemset/problem/1291 题意:就是一个三维的空间里,按照 ...

  9. Hiho----无间道之并查集

    题目: 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小Ho决定趁着这朗朗春光出去 ...

随机推荐

  1. 设置MyEclipse的右击新建后面的选项

    转自:http://blog.sina.com.cn/s/blog_929b09ac010197g6.html,做了修改 最近发现在MyEclipse右击后,新建后面的菜单选项太少了,新建一个文件,还 ...

  2. PHP的输出缓冲区

    什么是缓冲区?简单而言,缓冲区的作用就是,把输入或者输出的内容先放进内存,而不显示或者读取.至于为什么要有缓冲区,这是一个很广泛的问题,如果有兴趣,可以在网山找下资料.其实缓冲区最本质的作用就是,协调 ...

  3. mac下Apache添加限速模块mod_bw

    官方文档: Apache2 - Mod_bw v0.7 Author : Ivan Barrera A. (Bruce) HomePage : Http://Ivn.cl/apache & h ...

  4. javascript正则

      <script type="text/javascript"> //去除两边空格,如果要去除所有空格,使用/\s*即可/ String.prototype.trim ...

  5. java listener实现定时任务

    使用java ServletContextListener 实现各种简单定时任务. 1. 创建ServletContextListener,在3.0版本的web.xml中不再需要添加listener的 ...

  6. 在OC中调用Swift类中定义delegate出现:Property 'delegate' not found on object of type ...

    找了许久没找到答案, 在下面的链接中, 我解决了这个问题: http://stackoverflow.com/questions/26366082/cannot-access-property-of- ...

  7. C#string与char互转

    string s = "asdf"; //字符转char char[] c = s.ToCharArray(); Console.WriteLine(s[]); //char转st ...

  8. Fling!

    算法:深搜 很不错的一道题!!! Fling is a kind of puzzle games available on phone. This game is played on a board ...

  9. IOS添加自定义字体库

    1.将需要的字体库xxx.ttf添加到工程中,注意一定要在copy bundle resources中存在,如果没有添加上去 2.在info.plist 文件中添加 fonts provided by ...

  10. destoon系统商城加淘宝客按钮方法

    destoon系统很多喜欢运营B2B的站长都在用,其中的商城模块常常被用来做淘宝客,其中的难点是如何把购买按钮做成淘宝客地址,这个问题的修改在论坛上被叫价50元,下面小编把这个实用的方法分享下,希望对 ...