-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10507.cpp
More file actions
71 lines (58 loc) · 1.56 KB
/
uva10507.cpp
File metadata and controls
71 lines (58 loc) · 1.56 KB
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
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<map>
using namespace std;
int main() {
string s;
istringstream iss;
while(getline(cin, s), s.length()) {
int nslept, nedges;
nslept = stoi(s);
getline(cin, s);
nedges = stoi(s);
getline(cin, s);
set<char> awake;
for (char c : s) {
awake.insert(c);
}
map<char, vector<char>> graph;
for(int i=0; i < nedges; i++) {
getline(cin, s);
graph[s[0]].push_back(s[1]);
graph[s[1]].push_back(s[0]);
}
int currawake = awake.size();
int prevawake;
int nyears=0;
do {
vector<char> newawake;
prevawake = currawake;
for (auto v : graph) {
if (awake.count(v.first)) {
continue;
}
int nawake = 0;
for (char c : v.second) {
if (awake.count(c)) {
nawake++;
}
}
if (nawake > 2)
newawake.push_back(v.first);
}
for (auto c : newawake)
awake.insert(c);
currawake = awake.size();
nyears++;
} while (prevawake != currawake);
if (currawake == nslept) {
printf("WAKE UP IN, %d, YEARS\n", nyears-1);
} else {
printf("THIS BRAIN NEVER WAKES UP\n");
}
getline(cin, s);
}
}