#!/usr/bin/env python3
# nodes
#
# Read in lists of node neighbors, and output complete list of all neighbors
#
# nodeA nodeB
# nodeC nodeD
class NodeList:
def __init__(self):
self.nodes = {}
self.groups = 0
def add_pair(self, n1, n2): # add a pair of nodes
self.add_node(n1, n2) # they are neighbors
self.add_node(n2, n1) # to each other
def add_node(self, n1, n2):
if n1 not in self.nodes:
self.nodes[n1] = []
if n2 not in self.nodes[n1]: # add n2 only if not already a link
self.nodes[n1].append(n2)
self.groups += 1
def neighbors(self):
return list(map(lambda k: sorted(self.nodes[k]), sorted(self.nodes.keys())))
nodes = NodeList()
while True:
try:
line = input()
nums = [int(x) for x in line.