Skip to content

Commit 7df443a

Browse files
authoredOct 2, 2021
Create Discount-on-crackers.cpp
1 parent 5f86947 commit 7df443a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <bits/stdc++.h>
2+
#define endl "\n"
3+
#define ll long long
4+
#define M 1000000007
5+
using namespace std;
6+
vector<ll> v[26];
7+
bool flag[26][26];
8+
void mark(int x,int y)
9+
{
10+
flag[x][y]=true;
11+
for(auto b : v[y])
12+
if(!flag[x][b])
13+
mark(x,b);
14+
}
15+
void solve()
16+
{
17+
for(int i=0;i<26;i++)v[i].clear();
18+
memset(flag,false,sizeof(flag));
19+
string s,t;
20+
cin>>s>>t;
21+
int n;
22+
cin>>n;
23+
while(n--)
24+
{
25+
string c;
26+
cin>>c;
27+
v[c[0]-'a'].push_back(c[3]-'a');
28+
}
29+
if(s.length()!=t.length())
30+
{
31+
cout<<"NO"<<endl;
32+
return;
33+
}
34+
for(int i=0;i<26;i++)
35+
{
36+
flag[i][i]=true;
37+
for(auto a : v[i])
38+
if(!flag[i][a])
39+
mark(i,a);
40+
}
41+
bool ans=true;
42+
for(int i=0;i<s.length() && ans;i++)if(!flag[s[i]-'a'][t[i]-'a'])ans=false;
43+
cout<<(ans ? "YES" : "NO")<<endl;
44+
}
45+
int main()
46+
{
47+
ios_base::sync_with_stdio(0);
48+
cin.tie(0);
49+
cout.tie(0);
50+
int t=1;
51+
cin>>t;
52+
while(t--)
53+
solve();
54+
return 0;
55+
}

0 commit comments

Comments
 (0)