-
Notifications
You must be signed in to change notification settings - Fork 19
/
brexit.java
60 lines (42 loc) · 1.18 KB
/
brexit.java
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
import java.util.HashMap;
import java.util.HashSet;
public class brexit {
static HashSet<Integer> left = new HashSet<>();
static HashMap<Integer , HashSet<Integer>> map = new HashMap<>();
static HashMap<Integer , Integer> sizes = new HashMap<>();
public static boolean half(int c) {
return map.get(c).size() <= sizes.get(c) / 2.0;
}
public static void leave(int c) {
left.add(c);
for (int x : map.get(c))
map.get(x).remove(c);
for (int x : map.get(c))
if (half(x))
leave(x);
map.get(c).clear();
}
public static void main(String[] args) {
Kattio scan = new Kattio(System.in);
scan.getInt();
int edges = scan.getInt();
int country = scan.getInt();
int first = scan.getInt();
for (int i = 0; i < edges; i++)
{
int x = scan.getInt();
int y = scan.getInt();
if (!map.containsKey(x))
map.put(x , new HashSet<>());
map.get(x).add(y);
if (!map.containsKey(y))
map.put(y , new HashSet<>());
map.get(y).add(x);
}
for (int x : map.keySet())
sizes.put(x , map.get(x).size());
leave(first);
System.out.println(half(country) ? "leave" : "stay");
scan.close();
}
}