Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2023-01-19-00.43.24
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define all(we) we.begin(),we.end()
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define nl '\n'
- class Node{
- public:
- bool endd;
- Node *child[15];
- Node()
- {
- endd=false;
- for(ll i=0;i<13;i++) child[i]=NULL;
- }
- };
- void Insert(Node *cur,string a)
- {
- ll n=a.size();
- for(ll i=0;i<n;i++)
- {
- if(cur->child[a[i]-'0']==NULL)
- {
- cur->child[a[i]-'0'] = new Node();
- }
- cur = cur->child[a[i]-'0'];
- }
- cur->endd=true;
- }
- bool Search(Node *cur, string a,ll ind)
- {
- if(ind==a.size()) return 1;
- if(cur->endd==true) return 0;
- return Search(cur->child[a[ind]-'0'],a,ind+1);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll n,m,i,j,k,l;
- cin>>n;
- string a[n+4];
- Node *root = new Node();
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- Insert(root,a[i]);
- }
- l=0;
- for(i=0;i<n;i++)
- {
- if(!Search(root,a[i],0))
- {
- l=1;
- break;
- }
- }
- if(l) cout<<"NO"<<nl;
- else cout<<"YES"<<nl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment