题目链接 : http://hihocoder.com/contest/hiho14/problem/1
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
const int maxn=1e5+10;
map<string, int> mm;
int p[maxn];
int find_fri(int x)
{
if( x==p[x] ) return x;
return p[x]=find_fri(p[x]);
}
int main()
{
for(int i=0; i<maxn; i++) p[i]=i;
int n;
cin>>n;
int op, st=0;
string a, b;
for(int i=0; i<n; i++)
{
cin>>op>>a>>b;
mm.insert(pair<string, int>(a, st++));
mm.insert(pair<string, int>(b, st++));
int x=find_fri(mm[a]);
int y=find_fri(mm[b]);
if( !op )
{
if( x!=y ) p[x]=y;
}else
{
if( x==y ) printf("yes\n");
else printf("no\n");
}
}
return 0;
}