插入字典树:
class woca
{
public:
int son,brother;
char p;
}a[100000];
string A;
void build_tree(string A)
{
int l=A.length();
int now=1;
for(int i=0;i<l;i++)
{
if(a[now].son==0)
{
a[++sum].p=A[i];
a[now].son=sum;
now=sum;
}
else
{
now=a[now].son;
while(a[now].p!=A[i]&&a[now].brother!=0)
now=a[now].brother;
if(a[now].p!=A[i])
{
sum++;
a[now].brother=sum;
a[sum].p=A[i];
now=sum;
}
}
}
}