P2256 一中校运会之百米跑
作者:互联网
思路:
变种后的并查集,用map<string,string>来存。
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
#define ll long long
map<string,string>f;
string find(string x)
{
if(f[x] != x)
return f[x] = find(f[x]);
return f[x];
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++)
{
string a;
cin>>a;
f[a] = a;
}
while(m--)
{
string a,b;
cin>>a>>b;
f[find(a)] = f[find(b)];
}
int k;
cin>>k;
while(k--)
{
string a,b;
cin>>a>>b;
if(f[find(a)] == f[find(b)])
printf("Yes.\n");
else
printf("No.\n");
}
}
标签:校运会,const,string,P2256,cin,一中,int,printf,find 来源: https://blog.csdn.net/p15008340649/article/details/114310558