_what

博客园 首页 新随笔 联系 订阅 管理
/**/
#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:
*/
posted on 2019-10-14 21:21  _what  阅读(143)  评论(0编辑  收藏  举报