求助大佬看看怎么错了,或者给个题解,谢谢了
作者:
LYMY
,
2023-10-05 12:07:35
,
所有人可见
,
阅读 85
https://oj.czos.cn/p/1508
#include<iostream>
#include<unordered_map>
#include<cstring>
#include<algorithm>
using namespace std;
unordered_map<string,string> p;
string find(string x){
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
}
int main(){
string s,t,father;
while(cin>>s){
if(s=="$") break;
t=s.substr(1,s.size()-1);
if(s[0]=='#'){
father=t;
if(!p.count(father)) p[father]=father;
}
else if(s[0]=='+') p[t]=t,p[find(t)]=find(father);
else cout<<t<<" "<<p[t]<<endl;
}
return 0;
}
https://www.acwing.com/solution/content/206499/
哈希表
有可能冲突吧
怎么个冲突法,可以详细说说吗