Phone List
POJ – 3630
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#define maxn 10005
using namespace std;
int tot;
int flag;
int n;
struct node
{
int ch[11];
int f;
void init()
{
memset(ch,0,sizeof(ch));
f=0;
}
}tr[100005];
void Insert(char *p)
{
int now=0;
for(int i=0;p[i];i++)
{
int tem=p[i]-'0';
if(!tr[now].ch[tem])
{
tr[now].ch[tem]=++tot;
tr[tot].init();
}
now=tr[now].ch[tem];
if(tr[now].f)flag=1;
}
for(int i=1;i<=9;i++)if(tr[now].ch[i])flag=1;
tr[now].f=1;
}
int main()
{
int t;
cin>>t;
while(t--)
{
tot=0;
flag=0;
tr[0].init();
cin>>n;
char s[15];
for(int i=0;i<n;i++)
{
scanf("%s",s);
Insert(s);
}
if(flag)printf("NO\n");
else puts("YES");
}
}