最后两个点超时,大佬帮忙优化一下,谢谢
#include<bits/stdc++.h>
using namespace std;
char a;
string s,ss[100000];
int t,g,w,i,f[100000];
int zhao(string s){
int i;
for(i=1;i<=w;i++) if(ss[i]==s) return i;
ss[++w]=s;
return w;
}
int find(int x){
if(f[x]!=x) f[x]=find(f[x]);
return f[x];
}
int main(){
for(i=1;i<=50000;i++) f[i]=i;
while(1){
cin>>a;
if(a=='$') break;
cin>>s;
if(a=='#') g=zhao(s);
if(a=='+'){
t=zhao(s);
f[find(t)]=f[find(g)];
}
if(a=='?') cout<<s<<' '<<ss[find(zhao(s))]<<endl;
}
}