QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864986 | #9726. AUS | qmqcbhc | RE | 0ms | 0kb | C++20 | 1.2kb | 2025-01-21 13:00:26 | 2025-01-21 13:00:26 |
answer
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
ll t,n,m;
ll a[30];
void init_set(int n){
for(int i=1; i<=n; i++){
a[i]=i;
}
}
int find_set(int x){
if(x != a[x]) a[x]=find_set(a[x]); //压缩路径
return a[x];
}
void merge_set(int x, int y){
x = find_set(x);
y = find_set(y);
if(x!=y) a[x]=a[y]; //x以y为父
}
void fio(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve(){
init_set(30);
string str1,str2,str3;
ll n1,n2,n3;
cin >> str1 >> str2 >> str3;
n1=str1.length();
n2=str2.length();
n3=str3.length();
if(n1!=n2){
cout << "NO"<< endl;
return;
}
if(n1==n2 && n1!=n3){
cout << "YES" << endl;
return;
}
else{
for(int i=0; i<n1; i++){
ll t1=str1[i]-'a'+1;
ll t2=str2[i]-'a'+1;
//cout << t1 << " " << t2 << endl;
merge_set(t1,t2);
}
for(int i=0; i<n1; i++){
ll t1=str1[i]-'a'+1;
ll t2=str3[i]-'a'+1;
if(find_set(t1)!=find_set(t2)){
cout << "YES"<< endl;
return;
}
}
cout << "NO" << endl;
}
}
signed main()
{
fio();
cin >> t;
//t=1;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
4 abab cdcd abce abab cdcd abcd abab cdcd abc x yz def