-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelensson.cpp
72 lines (67 loc) · 1.43 KB
/
changelensson.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
struct node{
char f, l;
}node[1000004];
int cnt = 0;
bool flag = false;
int v[1000004];
void dfs(int a);
int main()
{
char str[100004];
while((scanf("%s", str)) != EOF){
flag = false;
if(str[0] == '0'){
printf("No.\n");
continue;
}
int i = 0;
node[i].f = str[0];
node[i++].l = str[strlen(str) - 1];
// memset(v, 1, sizeof(v));
// for(int i = 0; i < 100; i++){
// printf("%d ", v[i]);
// }
while((scanf("%s", str)) != EOF){
if(str[0] == '0'){
break;
}
node[i].f = str[0];
node[i++].l = str[strlen(str) - 1];
}
cnt = i;
for(i = 0; i < cnt; i++){
if(node[i].f == 'b'){
memset(v, 0, sizeof(v));
v[i] = 1;
dfs(i);
}
if(flag){
break;
}
}
if(!flag){
printf("No.\n");
}else{
printf("Yes.\n");
}
}
return 0;
}
void dfs(int a){
if(node[a].l == 'm'){
flag = true;
return;
}else{
for(int i = 0; i < cnt; i++){
if(node[i].f == node[a].l && v[i] == 0){
v[i] = 1;
dfs(i);
v[i] = 0;
}
}
}
}