#3 #4 WA
查看原帖
#3 #4 WA
807584
mengqifeng楼主2023/8/7 16:31
#include <iostream>
#include <map>
using namespace std;
map<string,string>fa;
int n,m,k;
string find(string x)
{
	if(fa[x]==x)return x;
	return fa[x]=find(fa[x]);
}
void merge(string x,string y)
{
	string q=find(x);
	string p=find(y);
	if(q!=p)fa[x]=y;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		string x;
		cin>>x;
		fa[x]=x;
	}
	for(int i=1;i<=m;i++)
	{
		string a,b;
		cin>>a>>b;
		merge(a,b);
	}
	cin>>k;
	while(k--)
	{
		string a,b;
		cin>>a>>b;
		if(find(a)!=find(b))cout<<"No.\n";
		else cout<<"Yes.\n";
	}
	return 0;
}
2023/8/7 16:31
加载中...