···2525 next_ports = ports + [port]
2626 strength = bridge_strength(next_ports)
27272828+ # See if we can incorporate any `X/X` components
2929+ strength += sum(2 * p for p in BRIDGE_EXTRAS if p in next_ports)
3030+2831 strongest = max(strongest, strength)
2932 longest = max(longest, strength)
3033···37403841BRIDGES = []
3942BRIDGE_PORTS = defaultdict(list)
4343+BRIDGE_EXTRAS = [] # tracks components of type `X/X`
40444141-for i, line in enumerate(fileinput.input()):
4242- x, y = [int(x) for x in line.split('/')]
4545+for line in fileinput.input():
4646+ x, y = (int(x) for x in line.split('/'))
43474444- BRIDGES.append((x, y))
4545- BRIDGE_PORTS[x].append(i)
4646- BRIDGE_PORTS[y].append(i)
4848+ if x != y:
4949+ i = len(BRIDGES)
5050+ BRIDGES.append((x, y))
5151+ BRIDGE_PORTS[x].append(i)
5252+ BRIDGE_PORTS[y].append(i)
5353+ else:
5454+ BRIDGE_EXTRAS.append(x)
47554856for i in BRIDGE_PORTS[0]:
4957 strongest, longest = bridge_bfs(i, 0)