样例全过,可全部T掉了
查看原帖
样例全过,可全部T掉了
662413
lmy_2011楼主2023/1/29 19:58
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline void write(int x)
{
	if(x<0) 
        putchar('-'),x=-x;
	if(x>9)
		write(x/10);
	putchar(x % 10 + '0');
	return;
}
int n=read(),m=read(),p;
map<string,string> father;
/*void init(){
	for(int i=1;i<=n;i++)
		father[i]=i;
	return;	
}*/
string find(string x){
	if(father[x]==x)
		return x;
	return father[x]=find(father[x]);
}
void un(string x,string y){
	x=find(x);
	y=find(y);
	if(x!=y)
		father[y]=x;
	return;
}
int main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);
   	cout.tie(0);
   	//init();
	for(int i=1;i<=n;i++){
		string name;
		std::cin>>name;
		father[name]=name;
	}
	for(int i=1;i<=m;i++){
		string mi,mj;
		std::cin>>mi>>mj;
		un(mi,mj);
	}
	p=read();
	for(int i=1;i<=p;i++){
		string pi,pj;
		std::cin>>pi>>pj;
		if(find(pi)==find(pj))
			puts("Yes.");
		else
			puts("No.");
	}
	return 0;
} 
2023/1/29 19:58
加载中...