#include <bits/stdc++.h> #define int long long #define PII pair<int,int> #define ll long long #define endl '\n' using namespace std; const int N=2e5+10,M=5010; int a[N],b[N],pre[N]; int p[N]; int find(int x) { if(x!=p[x]) { p[x]=find(p[x]); } return p[x]; } signed main() { cin.tie(0);cout.tie(0); ios::sync_with_stdio(0); int n,m;cin>>n>>m; unordered_map<string,int>mp; for(int i=1;i<=n;i++) { string str;cin>>str; mp[str]=i; } for(int i=1;i<=n;i++)p[i]=i; for(int i=1;i<=m;i++) { string a,b;cin>>a>>b; int x=mp[a],y=mp[b]; int px=find(x),py=find(y); if(px!=py) { p[px]=py; } } int q;cin>>q; for(int i=1;i<=q;i++) { string a,b;cin>>a>>b; int x=mp[a],y=mp[b]; int px=find(x),py=find(y); if(px!=py)cout<<"No."<<endl; else cout<<"Yes."<<endl; } }
P2256 一中校运会之百米跑
最新推荐文章于 2024-07-13 13:36:16 发布