题目:http://acm.hdu.edu.cn/showproblem.php?pid=1181
这个输入太坑了。。。。。。。。
注意是一进队就就标记vis[]。。。。
还有该串挺大的。。。所以数组开大点,不然越界。。。。。
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;
const int INF = 1<<30;
bool vis[11111];
int g[55][55];
char c[11111];
void Bfs()
{
int q1 = 1, q2;
int i;
queue <int> q;
memset(vis, 0, sizeof(vis));
q.push(q1);
vis[q1] = 1;//一进队就标记vis
while (!q.empty())
{
q2 = q.front();
q.pop();
for (i = 0; i < 26; i++)
{
if (!vis[i] && g[q2][i] == 1)
{
if (i == 'm'-'a')
{
puts("Yes.");
return;
}
q.push(i);
vis[i] = 1;
}
}
}
puts("No.");
return;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t;
int n;
int i, j;
int l;
//int a, b, c;
memset(g, 0, sizeof(g));
while (~scanf("%s", c))
{
l = strlen(c);
g[c[0]-'a'][c[l-1]-'a'] = 1;
if (c[0] == '0')
{
Bfs();
memset(g, 0, sizeof(g));//清空
}
}
return 0;
}