QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864986#9726. AUSqmqcbhcRE 0ms0kbC++201.2kb2025-01-21 13:00:262025-01-21 13:00:26

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 13:00:26]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [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

output:


result: