hiho week 14 register

Ended

Participants:423

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-07 23:25:08

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
24
25
26
27
28
29
30
31
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
using namespace std;
int n,pa[100005],tol;
map<string,int> f;
int Find(int x){
    if(pa[x] == 0) return x;
    pa[x] = Find(pa[x]);
    return pa[x];
}
int main(){
    int op,x,y;
    string a,b;
    tol = 0;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&op);
        cin>>a>>b;
        if(!f[a]) f[a] = (++tol);
        if(!f[b]) f[b] = (++tol);
        x = f[a];
        y = f[b];
        x = Find(x);y = Find(y);
        if(!op){
            if(x != y) pa[x] = y;
        }
        else{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX