-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrie
More file actions
87 lines (78 loc) · 1.4 KB
/
trie
File metadata and controls
87 lines (78 loc) · 1.4 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
struct node
{
map<char,node*>mp;
ll cnt;
};
node* root=new node();
void insrt(string s)
{
node* latest=root;
for(ll i=0;i<s.size();i++)
{
if(latest->mp.count(s[i])==false)
{
latest->mp[s[i]]=new node();
}
latest=latest->mp[s[i]];
latest->cnt++;
}
latest->cnt=-1;
}
ll ans=0;
ll ans1=0;
ll getans(string s)
{
node* latest=root;
for(ll i=0;i<s.size();i++)
{
latest=latest->mp[s[i]];
}
if((latest->cnt)!=-1)
return 0;
else
return 1;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t,i,j,l,n,m,x,k,kk,r,y,c;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
}
sort(a,a+n,fun);
for(i=0;i<n;i++)
{
insrt(a[i].s);
}
ll temp=1;
for(i=0;i<n;i++)
{
if(!getans(a[i].s))
{
cout<<"NO\n";
temp=0;
break;
}
}
if(temp)
cout<<"YES\n ";
}
return 0;
}