QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#833994 | #9726. AUS | remain11# | RE | 0ms | 0kb | C++20 | 1.1kb | 2024-12-27 09:41:40 | 2024-12-27 09:41:40 |
answer
#include <iostream>
#include <cassert>
using namespace std;
int fa[26];
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int merge(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
}
void solve() {
for (int i = 0; i < 26; ++i) fa[i] = i;
string a, b, c;
cin >> a >> b >> c;
int cat[26], cnt = 0;
for (int i = 0; i < 26; ++i) cat[i] = -1;
if (a.length() != b.length()) {
cout << "NO\n";
return;
}
if (a.length() != c.length()) {
cout << "YES\n";
return;
}
int n = a.length();
for (int i = 0; i < n; ++i) {
int aa = find(a[i] - 'a');
int bb = find(b[i] - 'a');
if (aa != bb) merge(aa, bb);
}
for (int i = 0; i < n; ++i) {
int aa = find(a[i] - 'a');
int cc = find(c[i] - 'a');
if (aa != cc) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 abab cdcd abce abab cdcd abcd abab cdcd abc x yz def