#pragma warning ( disable: 4786 )
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string> svec;
bool find,havem1,havem2;
int s[10000];
void dfs( int i )
{
if( svec[i][svec[i].size()-1] == 'm' )
{
find=true;
return ;
}
for( int j=0;j<svec.size();j++ )
{
if( svec[i][svec[i].size()-1] == svec[j][0] && s[j]==0 )
{
s[j]=1;
dfs( j );
}
}
}
int main()
{
string str;
bool cntb=false,cntm=false;
find=false;
havem1=false;
havem2=false;
while( cin>>str )
{
memset( s,0,sizeof(s) );
if( str.size()==1 && str[0] != '0' )
continue;
if( str[0]=='0' )
{
if( !(havem1 && havem2 ))
{
printf("No./n");
find=false;
havem1=false;
havem2=false;
svec.clear();
memset( s,0,sizeof(s) );
continue;
}
for( int i=0;i<svec.size();i++ )
{
if( find == true )
break;
if( svec[i][0]=='b' )
dfs( i );
}
if( find == true )
printf("Yes./n");
else
printf("No./n");
find=false;
havem1=false;
havem2=false;
svec.clear();
memset( s,0,sizeof(s) );
}
else
{
svec.push_back(str);
if(str[str.size()-1]=='m')
havem2=true;
if( str[0]=='m' )
havem1=true;
}
}
return 0;
}
悲剧啊,原来Runtime Error(STACK_OVERFLOW)的原因是递归过多。。还好汇编学的好。。分析出来了。。