#include<bits/stdc++.h>
using namespace std;
long long n, t, i, last=1, cur, k, x, fl;
string s;
struct node{
bool endmark;
int next[11];
}r[100009];
void new_trie(int cur){
for(int zz=0; zz<10; zz++){
r[cur].next[zz]=-1;
}
r[cur].endmark=false;
}
void insrt(){
cur=0, k=s.size();
for(int z=0; z<k; z++){
x=(int)s[z]-48;
if(r[cur].next[x]==-1){
r[cur].next[x]=last;
new_trie(last++);
cur=r[cur].next[x];
}
else{
cur=r[cur].next[x];
if(r[cur].endmark==true)fl=1;
if(z==k-1) fl=1;
}
if(fl==1) break;
}
r[cur].endmark=true;
}
int main(){
cin>>t;
while(t--){
cin>>n;
fl=0, last=1;
new_trie(0);
for(i=0; i<n; i++){
cin>>s;
insrt();
}
if(fl==1) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
|
Monday, October 31, 2016
Solution of UVa 11362-Phone List
See the problem UVa-11362
Subscribe to:
Post Comments (Atom)
-
#include<bits/stdc++.h> #define ll long long using namespace std ; ll n , k , t_case ; ll bigmod ( ll b , ll p , ll m...
-
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 ...
-
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 3...
No comments:
Post a Comment