[Python/2019] Restructure solutions
This commit is contained in:
parent
40e767096e
commit
fb42493fff
63 changed files with 1393 additions and 1739 deletions
39
Python/2019/06.py
Normal file
39
Python/2019/06.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2019, 6)
|
||||
|
||||
graph = {}
|
||||
for line in input.splitlines():
|
||||
a, b = line.split(")")
|
||||
graph.setdefault(a, set()).add(b)
|
||||
|
||||
out = 0
|
||||
Q = [("COM", 0)]
|
||||
while Q:
|
||||
node, count = Q.pop(0)
|
||||
out += count
|
||||
for child in graph.get(node, set()):
|
||||
Q.append((child, count + 1))
|
||||
print(out)
|
||||
|
||||
|
||||
graph = {}
|
||||
for line in input.splitlines():
|
||||
a, b = line.split(")")
|
||||
graph.setdefault(a, set()).add(b)
|
||||
graph.setdefault(b, set()).add(a)
|
||||
|
||||
Q = [("YOU", 0)]
|
||||
visited = set()
|
||||
while Q:
|
||||
node, dist = Q.pop(0)
|
||||
|
||||
if node in visited:
|
||||
continue
|
||||
visited.add(node)
|
||||
|
||||
if node == "SAN":
|
||||
print(dist - 2)
|
||||
|
||||
for child in graph.get(node, set()):
|
||||
Q.append((child, dist + 1))
|
Loading…
Add table
Add a link
Reference in a new issue