hiho week 14 register

Ended

Participants:423

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-06 19:12:54

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<map>
#define maxn 300000
using namespace std;
int p[maxn],op;
int F(int x){return p[x]==x ? x:F(p[x]);}
void U(int x,int y){x=F(x);y=F(y);p[y]=x;}
map<string,int>mp;
int cnt=1,n;
int main(){
    cin>>n;
    for(int i=0;i<=maxn;i++) p[i]=i;
    for(int i=0;i<n;i++){
        string s1,s2;
        cin>>op>>s1>>s2;
        if(mp[s1]==0)mp[s1]=cnt++;
        if(mp[s2]==0)mp[s2]=cnt++;
        if(op==0) U(mp[s1],mp[s2]);
        else if(F(mp[s1])==F(mp[s2])) cout<<"yes\n";
        else cout<<"no\n";
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX