#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
string s;
int mp[27][27];
int vis[27];
int bfs()
{
cle(vis);
queue<int>q;
q.push(1);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=0;i<26;i++)
{
if(!vis[i]&&mp[u][i])
{
if(i==12)return 1;
q.push(i);
vis[i]=1;
}
}
}
return 0;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>s)
{
cle(mp);
mp[s[0]-'a'][s[s.size()-1]-'a']=1;
while(cin>>s)
if(s[0]=='0')break;
else mp[s[0]-'a'][s[s.size()-1]-'a']=1;
if(bfs())cout<<"Yes."<<endl;
else cout<<"No."<<endl;
}
return 0;
}
HDU 1181 变形课
最新推荐文章于 2019-08-14 06:50:48 发布
http://acm.hdu.edu.cn/showproblem.php?pid=1181
BFS搜索建树,找到一条边 b~m那么就输出yes 否则输出no