DFS
HDU1181 http://acm.hdu.edu.cn/showproblem.php?pid=1181
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string.h> 5 using namespace std; 6 struct point{ 7 char first; 8 char last; 9 }p[1111]; 10 int flag,k; 11 char s[1111]; 12 char vis[1111],ma[1111]; 13 void dfs(char c){ 14 if(c=='m'){ 15 flag=1; 16 return; 17 } 18 for(int j=0;j<k;j++){ 19 if(vis[j]==0&&p[j].first==c){ 20 vis[j]=1; 21 dfs(p[j].last); 22 } 23 } 24 return ; 25 } 26 int main() 27 { 28 while(~scanf("%s",&s)){ 29 if(strcmp(s,"0")==0)continue; 30 p[0].first=s[0]; 31 p[0].last=s[strlen(s)-1]; 32 k=1; 33 while(~scanf("%s",&s)&&strcmp(s,"0")!=0) 34 {p[k].first=s[0]; 35 p[k].last=s[strlen(s)-1]; 36 //cout<<p[k].first<<p[k].last<<endl; 37 k++; 38 39 } 40 flag=0; 41 for(int i=0;i<k;i++){ 42 if(p[i].first=='b'){ 43 memset(vis,0,sizeof(vis)); 44 vis[i]=1; 45 dfs('b'); 46 } 47 if(flag==1)break; 48 } 49 if(flag==1) 50 cout<<"Yes."<<endl; 51 else cout<<"No."<<endl; 52 } 53 }
你若盛开,清风自来...