-
Notifications
You must be signed in to change notification settings - Fork 0
/
00168.cpp
67 lines (61 loc) · 1.11 KB
/
00168.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
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph(26);
int minotaur,theseus,k;
bitset<26> candle;
void gen_graph(char *s)
{
char u = s[0] - 'A';
graph.assign(26,vector<int>());
for(int i = 1;s[i];i++)
{
if(s[i] == ':' || s[i] == '.') continue;
if(s[i] == ';') u = s[++i] - 'A';
else graph[u].push_back(s[i] - 'A');
}
}
int flee()
{
for(vector<int>::iterator it = graph[minotaur].begin();it != graph[minotaur].end();it++)
if(*it != theseus && !candle[*it]) return *it;
return -1;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
char s[300];
int t,cav;
while(gets(s))
{
if(s[0] == '#') break;
gen_graph(strtok(s," "));
minotaur = strtok(NULL," ")[0] - 'A';
theseus = strtok(NULL," ")[0] - 'A';
k = atoi(strtok(NULL," "));
cav = 0;
candle.reset();
while(true)
{
t = flee();
if(cav == k)
{
printf("%c ",theseus + 'A');
candle.set(theseus);
cav = 0;
}
cav++;
if(t == -1)
{
printf("/%c\n",minotaur + 'A');
break;
}
else
{
theseus = minotaur;
minotaur = t;
}
}
}
return 0;
}