#Vertex using Adjacency List

class Vertex:
    def __init__(self,n):
        self.name = n 
        self.neighbours  =set()
    def add_neighbor(self,v):
        self.neighbor.add(v) 

class Graph:

    vertices = {} 

    def add_vertex(self,vertex):
        if isinstance(vertex,Vertex) and vertex.name not in self.vertices:
            self.vertices[vertex.name] = vertex 
            return True 
        else:
            return False 
    
    def add_edge(self,u,v): 
        if u in self.vertices and v in self.vertices:
            self.vertices[u].add_neighbor(v)
            self.vertices[v].add_neighbor(u) 
            return True 
        else:
            return False 
    def print_graph(self):
        for key in sorted(list(self.vertices.keys())):
            print(key,sorted(list(self.vertices[key].neighbors)))
#Vertex using Adjacency List

class Vertex:
    def __init__(self,n):
        self.name = n 
        self.neighbours  =set()
    def add_neighbor(self,v):
        self.neighbor.add(v) 

class Graph:

    vertices = {} 

    def add_vertex(self,vertex):
        if isinstance(vertex,Vertex) and vertex.name not in self.vertices:
            self.vertices[vertex.name] = vertex 
            return True 
        else:
            return False 
    
    def add_edge(self,u,v): 
        if u in self.vertices and v in self.vertices:
            self.vertices[u].add_neighbor(v)
            self.vertices[v].add_neighbor(u) 
            return True 
        else:
            return False 
    def print_graph(self):
        for key in sorted(list(self.vertices.keys())):
            print(key,sorted(list(self.vertices[key].neighbors)))
#Vertex using Adjacency List