text: #
  #  adjGraph
  #
  #  Created by Brad Miller on 2005-02-24.
  #  Copyright (c) 2005 Brad Miller, David Ranum, Luther College. All rights reserved.
  #
  
  import sys
  import os
  
  class Graph:
      def __init__(self):
          self.vertices = {}
          self.numVertices = 0
          
      def addVertex(self,key):
          self.numVertices = self.numVertices + 1
          newVertex = Vertex(key)
          self.vertices[key] = newVertex
          return newVertex
      
      def getVertex(self,n):
          if n in self.vertices:
              return self.vertices[n]
          else:
              return None
  
      def __contains__(self,n):
          return n in self.vertices
      
      def addEdge(self,f,t,cost=0):
              if f not in self.vertices:
                  nv = self.addVertex(f)
              if t not in self.vertices:
                  nv = self.addVertex(t)
              self.vertices[f].addNeighbor(self.vertices[t],cost)
      
      def getVertices(self):
          return list(self.vertices.keys())
          
      def __iter__(self):
          return iter(self.vertices.values())
                  
  class Vertex:
      def __init__(self,num):
          self.id = num
          self.adj=[]
          self.connectedTo = {}
          self.color = 'white'
          self.dist = sys.maxsize
          self.pred = None
          self.disc = 0
          self.fin = 0
          self.cost = {} 
  
      # def __lt__(self,o):
      #     return self.id < o.id
      
      def addNeighbor(self,nbr,cost=0):
          self.adj.append(nbr)
          self.cost[nbr] = cost
          self.connectedTo[nbr] = cost
          
      def setColor(self,color):
          self.color = color
          
      def setDistance(self,d):
          self.dist = d
  
      def setPred(self,p):
          self.pred = p
  
      def setDiscovery(self,dtime):
          self.disc = dtime
          
      def setFinish(self,ftime):
          self.fin = ftime
          
      def getFinish(self):
          return self.fin
          
      def getDiscovery(self):
          return self.disc
          
      def getPred(self):
          return self.pred
          
      def getDistance(self):
          return self.dist
          
      def getColor(self):
          return self.color
      
      def getConnections(self):
          return self.connectedTo.keys()
          
      def getWeight(self,nbr):
          return self.connectedTo[nbr]
                  
      def __str__(self):
          return str(self.id) + ":color " + self.color + ":disc " + str(self.disc) + ":fin " + str(self.fin) + ":dist " + str(self.dist) + ":pred \n\t[" + str(self.pred)+ "]\n"
      
      def getId(self):
          return self.id
  
      def getAdj(self):
          return self.adj 
  
  if __name__ == '__main__':
      class adjGraphTests():
          def __init__(self):
              self.tGraph = Graph()
          def testMakeGraph(self,conf=("1|2","1|3","2|4","3|4","4|1")):
              for line in conf:
                  fVertex, tVertex = line.split('|')
                  fVertex = int(fVertex)
                  tVertex = int(tVertex)
                  self.tGraph.addEdge(fVertex,tVertex)
              for i in self.tGraph:
                  adj = i.getAdj()
                  for k in adj:
                      print(i, k)
  
      a=adjGraphTests()
      a.testMakeGraph()
      print("End")
                
  