hiho week 14 register

Ended

Participants:423

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-04 22:27:01

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 <cstdio>
#include <cstring>
const int N=100010;
#define C(c) c>'Z'?c-'a'+26:c-'A'
int e[N],x[N][26*2],c=0,d=0;
int add(){
    ++c;
    e[c]=0;
    memset(x[c],0,sizeof(x[c]));
    return c;
}
int find(char*s){
    int p=0,t;
    while(*s){
        t=C(*s);
        if(!x[p][t])x[p][t]=add();
        p=x[p][t];
        ++s;
    }
    return e[p]?e[p]:e[p]=++d;
}
char a[100],b[100];
int r[N],n,o,A,B;
int find(int i){return i==r[i]?i:r[i]=find(r[i]);}
int main(){
    for(scanf("%d",&n);n--;){
        scanf("%d%s%s",&o,a,b);
        A=find(a);B=find(b);
        if(!r[A])r[A]=A;
        if(!r[B])r[B]=B;
        A=find(A);B=find(B);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX