求助!!WA0分
查看原帖
求助!!WA0分
222479
鱼鱼号铲屎车楼主2021/1/26 10:57

这个题目我自己测过阳历已经通过了可是为啥已交上去就不对呢? 代码:

#include<bits/stdc++.h>
using namespace std;
map<string,string> mp;
string fatheryingshe(string n){
	if(mp[n] == n) {
		return n;
	}
	return mp[n] = fatheryingshe(mp[n]);
}
int main(){
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < n; i ++){
		string t;
		cin >> t;
		mp[t] = t;
	}
	for(int i = 0 ; i < m ; i ++){
		string t,t1;
		cin >> t >> t1;
		string t2 = fatheryingshe(t);
		string t3 = fatheryingshe(t1);
		if(t2 != t3){
			mp[t2] = t3;
		}
	}
	int k;
	cin >> k;
	for(int i = 0 ; i < k; i ++){
		string t,t1;
		cin >> t >> t1;
		string t2 = fatheryingshe(t);
		string t3 = fatheryingshe(t1);
		if(t2 != t3){
			cout << "NO";
			cout << '\n';
		} else {
			cout << "Yes\n";
		}
	}
	exit(0);
} 
2021/1/26 10:57
加载中...