forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrexit.cpp
71 lines (58 loc) · 1.31 KB
/
brexit.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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct country {
bool left;
int incoming;
int neighborsleft;
vector<int> neighbors;
};
int main() {
int c, p, x, l;
cin >> c >> p >> x >> l;
vector<country> v;
for(int i = 0; i < c+1; i++) {
country c;
c.left = false;
c.incoming = 0;
c.neighborsleft = 0;
v.push_back(c);
}
for(int i = 0; i < p; i++) {
int a, b;
cin >> a >> b;
v[a].incoming++;
v[a].neighborsleft++;
v[a].neighbors.push_back(b);
v[b].incoming++;
v[b].neighborsleft++;
v[b].neighbors.push_back(a);
}
queue<int> toprocess;
v[l].left = true;
for(auto i : v[l].neighbors) {
v[i].neighborsleft--;
toprocess.push(i);
}
while(toprocess.size() > 0) {
int c = toprocess.front();
toprocess.pop();
if(v[c].left) {
continue;
}
if(v[c].neighborsleft <= v[c].incoming / 2) {
v[c].left = true;
for(auto i : v[c].neighbors) {
v[i].neighborsleft--;
toprocess.push(i);
}
}
}
if(v[x].left) {
cout << "leave" << endl;
}
else {
cout << "stay" << endl;
}
}