0
已解决
刘景程
新手光能
新手光能
#include<bits/stdc++.h>
using namespace std;
queue<string> q;
int n;
string a[10001],b[10001];
map<string,string> m,m2;
map<string,bool> vis;
int ans;
signed main()
{
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a[i]>>b[i];
m[b[i]]=a[i];
m2[a[i]]=b[i];
}
string start;
cin>>start;
if(start.empty())
{
cout<<0;
return 0;
}
q.push(start);
vis[start]=1;
ans=1;
while(!q.empty())
{
string h=q.front();
if(h.empty())break;
q.pop();
map<string,string>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
string s1=it->first,s2=it->second;
if(h==s2&&!vis[s1])
{
vis[s1]=1;
q.push(s1);
ans++;
}
}
for(it=m2.begin();it!=m2.end();it++)
{
string s1=it->first,s2=it->second;
if(h==s1&&!vis[s2])
{
vis[s2]=1;
q.push(s2);
ans++;
}
}
}
cout<<ans;
}
70分代码。。。
发现这个测试点有bug:正确答案是3,我输出来个4...
32
add dda
dde daa
acb cdc
bdd daa
dad dec
ceb eac
dca eba
eae bee
eec cbb
dcb cac
dda cca
eac edd
cba aad
cbe ede
ecd eba
ada aab
ebc dca
dea ebc
bda cae
ebd daa
ded dcb
cca cac
bea cec
bab ecc
ccd acd
bdb bba
eda ebe
abe ebb
aeb adb
eed eea
dcd abe
cba abe
cba
求助大佬@栾峻岩