-
Notifications
You must be signed in to change notification settings - Fork 0
/
10507.cpp
66 lines (54 loc) · 1.3 KB
/
10507.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
#include<bits/stdc++.h>
using namespace std;
int visited [26];
int main()
{
int n,m;
string awake, tmp;
while (cin>>n)
{
vector<string> con;
map<char,int> mp;
cin>>m;
memset (visited, 0, sizeof(visited));
cin>>awake;
int x = 0;
for (int j=0;j<3;j++) if (mp.find(awake[j])==mp.end()) mp[awake[j]] = x++;
for(int i=0;i<m;i++) {
cin>>tmp;
con.push_back(tmp);
for (int j=0;j<2;j++) {
if (mp.find(tmp[j])==mp.end()) mp[tmp[j]] = x++;
}
}
if (n>mp.size()) {
printf ("THIS BRAIN NEVER WAKES UP\n");
continue;
}
for (int i=0;i<3;i++) visited[mp[awake[i]]] = 1;
int count = 3, ret=0;
while (count<n)
{
vector<int> to_mark;
for (map<char,int>::iterator it = mp.begin(); it!=mp.end(); it++)
{
int j = it->second;
if (visited[j]) continue;
int tcount = 0;
for (int k=0;k<con.size();k++)
{
if (mp[con[k][0]]==j && visited[mp[con[k][1]]]) tcount++;
else if (mp[con[k][1]]==j && visited[mp[con[k][0]]]) tcount++;
}
if (tcount>=3) to_mark.push_back (j);
}
count += to_mark.size();
if (to_mark.empty()) break;
for (int j=0;j<to_mark.size();j++) visited[to_mark[j]]=1;
ret++;
}
if (count<n) printf ("THIS BRAIN NEVER WAKES UP\n");
else printf ("WAKE UP IN, %d, YEARS\n", ret);
}
return 0;
}