-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23_LANParty.py
More file actions
47 lines (33 loc) · 843 Bytes
/
23_LANParty.py
File metadata and controls
47 lines (33 loc) · 843 Bytes
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
import collections, itertools
from lib import *
inp = get_input()
G = collections.defaultdict(set)
for l in inp:
a,b = l.split("-")
G[a].add(b)
G[b].add(a)
def all_connected(nodes):
for a,b in itertools.combinations(nodes, r=2):
if a not in G[b]:
return False
return True
L = len(max(G.values(), key=len))
p1 = None
p2 = None
for i in range(L, 1, -1):
F = set()
if p2 is not None and i != 2:
continue
for k,v in G.items():
for group in itertools.combinations(v, r=i):
if all_connected(group):
F.add(frozenset((k,*group)))
if i == 2:
p1 = 0
for group in F:
if any(x.startswith("t") for x in group):
p1 += 1
if len(F) == 1:
p2 = ",".join(sorted(F.pop()))
print(p1)
print(p2)