Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- ll tt;
- cin >> tt;
- while (tt--) {
- ll n;
- cin >>n;
- string s,t;
- cin >> s >> t;
- vector<ll>v(n);
- for (auto &i:v) cin >> i;
- map<char,vector<pair<ll,ll>>>m;
- for (int i=0; i<n; i++) {
- m[s[i]].push_back({v[i],i});
- }
- for (int i=0; i<n; i++) {
- int f=1;
- if (s[i]!=t[i]) {
- f=0;
- for (auto &x:m[t[i]]) {
- if (x.first==v[i]) {
- f=1;
- swap(s[i],s[x.second]);
- for (auto &y:m[s[i]]) {
- if (y.second==i) {
- swap(y.second,x.second);
- break;
- }
- }
- }
- if (f) break;
- }
- }
- if (!f) break;
- }
- if (s==t) cout << "YES" << endl;
- else cout << "NO" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment