hihocoder 1066 并查集
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
bool Sqrt(LL n) { return (LL)sqrt(n) * sqrt(n) == n; }
const double PI = acos(-1.0), ESP = 1e-10;
const LL INF = 99999999999999;
const int inf = 999999999, N = 1e5 + 5;
int n, op, fa[N], m, x, y;
char s[N];
map<string, int> mp;
int Find(int x)
{
int y = x;
for(; x != fa[x]; x = fa[x]);
return fa[y] = x;
}
int Read()
{
scanf("%s", s);
if(mp.count(s)) return mp[s];
mp[s] = ++m;
fa[m] = m;
return m;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
scanf("%d", &n);
while(n--) {
scanf("%d", &op);
x = Find(Read());
y = Find(Read());
if(op) x == y ? puts("yes") : puts("no");
else fa[x] = y;
}
return 0;
}
/*
input:
output:
modeling:
methods:
complexity:
summary:
*/
hihocoder 1066 并查集的更多相关文章
- hihocoder 1066 无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...
- [hihoCoder]无间道之并查集
题目大意: #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之, ...
- 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 题意:就是一个三维的空间里,按照 ...
- ACM学习历程—Hihocoder 1291 Building in Sandbox(dfs && 离线 && 并查集)
http://hihocoder.com/problemset/problem/1291 前几天比较忙,这次来补一下微软笔试的最后一题,这题是这次微软笔试的第四题,过的人比较少,我当时在调试B题,没时 ...
- hiho #1066 : 无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...
- HihoCoder第十四周:无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息--额,说远了,总之,小Hi和小H ...
- 【hihoCoder第十四周】无间道之并查集
就是基础的并查集.0代表合并操作,1代表查询操作.一开始以为会卡路径压缩,忐忑的交了一版裸并查集,结果AC了.数据还是很水的. 以后坚持做hiho,当额外的练习啦~ #include <bits ...
- hihoCoder 树结构判定(并查集)
思路:树满足两个条件: 1.顶点数等于边数加一 2.所有的顶点在一个联通块 那么直接dfs或者并查集就可以了. AC代码 #include <stdio.h> #include<st ...
- hihoCoder week14 无间道之并查集
并查集的基本使用 #include <bits/stdc++.h> using namespace std; ; int n, fa[N]; int cnt, tot; map<st ...
随机推荐
- Vuex4.x 简介及state、getters、mutations、actions详解(OptionApi 和 CompositionApi)
http://t.zoukankan.com/yaopengfei-p-15439203.html 作 者 : Yaopengfei(姚鹏飞) 博客地址 : http://www.cnbl ...
- C++实现线性表-顺序表的合并操作代码
#include<iostream>#include<cstdlib>//C++动态分配存储空间using namespace std;#define OK 1#define ...
- JAVASCRIPT 对有符号整型、无符号整型、浮点型、十六进制、二进制的数据处理
1.十六进制字符串转有符号整型,支持S8.S16.S32: function hexToInt(hex) { if(hex.length % 2 != 0) { hex = "0" ...
- codeforces思维题
1.Slime Escape 次数:0 2.Meeting on the Line 题解 次数:0 3.Ugu 自己完成了线段树解法,另一种解法未完成
- error Delete `␍` prettier/prettier 错误解决方案
问题根源: 罪魁祸首是git的一个配置属性:core.autocrlf 由于历史原因,windows下和linux下的文本文件的换行符不一致. Windows在换行的时候,同时使用了回车符CR(car ...
- L2 Cracia Final Update1 OpCodz
[87] Gracia Final Update 1 Client 00 SendLogOut 01 RequestAttack 03 RequestStartPledgeWar 04 Request ...
- npm config get prefer-offline
npm config get prefer-offline
- python 安装步骤
1.这个安装方法不需要配置环境变量 2. 3. 4.进入cmd,输入python -v
- Leetcode本地阅读器开发--01界面设计一
返回项目声明及目录:Leetcode本地阅读器开发--总声明 整个界面设计如下:后续可能会不断优化和加入新功能 1.启动后界面 2.进行具体题目搜索 3.进行分类搜索 本节主要介绍程序界面的绘制: 1 ...
- 安卓蓝牙协议栈中的RFCOMM状态机分析
1.1 数据结构 1.1.1 tRFC_MCB tRFC_MCB(type of rfcomm multiplexor control block的简写)代表了一个多路复用器.代表了RFCOMM规范 ...