http://acm.hdu.edu.cn/showproblem.php?pid=1181

直接bfs,等号写成赋值了,wa两次。。。

View Code
#include <stdio.h>
#include <string.h>
char s[200];
char graph[50][50];
char vis[50];
int q[50];
int bfs()
{
    int front=0,rear=1;
    int ch,i;
    q[0]=1;
    while(front<rear)
    {
        ch=q[front++];
        if(ch=='m'-'a')return 1;
        for(i=0;i<26;i++)
        {
            if(graph[ch][i]&&vis[i]==0)
            {
                vis[i]=1;
                q[rear++]=i;
            }
        }
    }
    return 0;
}
int main()
{
    while(gets(s))
    {
        if(strcmp(s,"0")==0)
        {
            printf(bfs()?"Yes.\n":"No.\n");
            memset(graph,0,sizeof(graph));
            memset(vis,0,sizeof(vis));
        }
        else
            graph[s[0]-'a'][s[strlen(s)-1]-'a']=1;
    }
    return 0;
}