Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int flag;
- int last,cur, len,id;
- string str;
- struct node
- {
- bool endmark;
- int next[13];
- } root[100000];
- void trie(int cur)
- {
- for (int i = 0; i < 10; i++)
- root[cur].next[i] = -1;
- root[cur].endmark=false;
- }
- void insert()
- {
- cur=0;
- len=str.size();
- for (int i = 0; i < len; i++)
- {
- id = str[i] - 48;
- if (root[cur].next[id]==-1)
- {
- root[cur].next[id]=last;
- trie(last++);
- cur = root[cur].next[id];
- }
- else
- {
- cur = root[cur].next[id];
- if(root[cur].endmark==true)
- {
- flag=1;
- }
- if(i==len-1)
- flag = 1;
- }
- if(flag==1)
- break;
- }
- root[cur].endmark = true;
- }
- int main()
- {
- int test;
- cin>>test;
- while(test--)
- {
- flag=0;
- last=1;
- trie(0);
- int n;
- cin>>n;
- for(int i=0; i<n; i++)
- {
- cin>>str;
- insert();
- }
- if(flag==1)
- cout<<"NO"<<endl;
- else
- cout<<"YES"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement