![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0ffbe82c29c4215e24f6ebcd4914665e.png)
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <sstream>
using namespace std;
char a[1000][2],b='b',m='m',str[100];
int n,flag,cnt,sum,avg;
bool vis[1000];
void dfs(char ch)
{
if(ch==m)
{
flag=1;
return;
}
if(flag==1) return;
for(int i=0;i<cnt;i++)
{
if(vis[i]==0&&a[i][0]==ch)
{
vis[i]=true;
dfs(a[i][1]);
vis[i]=false;
}
}
return;
}
int main()
{
cnt=0,flag=0;
while(gets(str))
{
int len=strlen(str);
if(str[0]=='0')
{
dfs(b);
if(flag==1) cout<<"Yes."<<endl;
else cout<<"No."<<endl;
memset(vis,0,sizeof(vis));
memset(a,0,sizeof(a));
cnt=0,flag=0;
continue;
}
a[cnt][0]=str[0],a[cnt][1]=str[len-1];
cnt++;
}
return 0;
}