## 【并查集】Wireless Network

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.

## 字典树模板

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x7fffffff
#define INFL 0x7fffffffffffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;

typedef struct Trie{
int v;
Trie *next[26];
}Trie;
Trie root;
void createTrie(char *str)
{
int len = strlen(str);
Trie *p = &root, *q;
for(int i=0; i<len; ++i)
{
int id = str[i]-'a';
if(p->next[id] == NULL)
{
q = (Trie *)malloc(sizeof(root));
q->v = 1;
for(int j=0; j<26; ++j)
q->next[j] = NULL;
p->next[id] = q;
p = p->next[id];
}
else
{
p->next[id]->v++;
p = p->next[id];
}
}
}

int findTrie(char *str)
{
int len = strlen(str);
Trie *p = &root;
for(int i=0; i<len; ++i)
{
int id = str[i]-'a';
p = p->next[id];
if(p == NULL)
return 0;
}
return p->v;
}
void dele(char *str,int n)
{
Trie *p = &root;
int len = strlen(str);
for(int i=0; i<len; ++i)
{
int id = str[i]-'a';
p = p->next[id];
p->v-=n;
}
for(int j=0; j<26; ++j)
{
p->next[j] = NULL;
}
}
int main()
{
int t;
char s1[10000],s2[10000];
for(int i=0;i<26;i++)
{
root.next[i]=NULL;
}
cin>>t;
while(t--)
{
scanf("%s%s",s1,s2);
if(s1[0]=='i')
{
createTrie(s2);
}
else if(s1[0]=='s')
{
int ans=findTrie(s2);
if(ans)
{
puts("Yes");
}
else
{
puts("No");
}
}
else
{
int cnt=findTrie(s2);
if(cnt)
{
dele(s2,cnt);
}
}
}
return 0;
}