  
  class Graph:
  
      def __init__(self):
          self.nodes = {}  # key = node id, val = node
  
      def add_node(self, id):
          node = Node(id)
          self.nodes[id] = node
          return node
  
      def add_edge(self, id_source, id_dest, weight=0):
          if id_source not in self.nodes:
              self.add_node(id_source)
          if id_dest not in self.nodes:
              self.add_node(id_dest)
          self.nodes[id_source].add_neighbor(self.nodes[id_dest], weight)
  
      def add_undirected_edge(self, source, dest, weight=0):
          self.add_edge(source, dest, weight)
          self.nodes[dest].add_neighbor(self.nodes[source], weight) 
</s> remove     "        self.nodes = {}  # key = node id, val = node\n",
    "\n",
    "    def add_node(self, id):\n",
    "        node = Node(id)\n",
    "        self.nodes[id] = node\n",
    "        return node\n",
    "\n",
    "    def add_edge(self, id_source, id_dest, weight=0):\n",
    "        if id_source not in self.nodes:\n",
    "            self.add_node(id_source)\n",
    "        if id_dest not in self.nodes:\n",
    "            self.add_node(id_dest)\n",
    "        self.nodes[id_source].add_neighbor(self.nodes[id_dest], weight)\n",
    "\n",
    "    def add_undirected_edge(self, source, dest, weight=0):\n",
    "        self.add_edge(source, dest, weight)\n",
    "        self.nodes[dest].add_neighbor(self.nodes[source], weight)"
 </s> add     "        self.nodes = {}  # Key = key, val = Node\n",
    "\n",
    "    def add_node(self, key):\n",
    "        if key is None:\n",
    "            raise Exception('Invalid key')\n",
    "        if key in self.nodes:\n",
    "            return self.nodes[key]\n",
    "        self.nodes[key] = Node(key)\n",
    "        return self.nodes[key]\n",
    "\n",
    "    def add_edge(self, source_key, dest_key, weight=0):\n",
    "        if source_key is None or dest_key is None:\n",
    "            raise Exception('Invalid key')\n",
    "        if source_key not in self.nodes:\n",
    "            self.add_node(source_key)\n",
    "        if dest_key not in self.nodes:\n",
    "            self.add_node(dest_key)\n",
    "        self.nodes[source_key].add_neighbor(self.nodes[dest_key],\n",
    "                                            weight)\n",
    "\n",
    "    def add_undirected_edge(self, source_key, dest_key, weight=0):\n",
    "        if source_key is None or dest_key is None:\n",
    "            raise Exception('Invalid key')\n",
    "        self.add_edge(source_key, dest_key, weight)\n",
    "        self.nodes[dest_key].add_neighbor(self.nodes[source_key],\n",
    "                                          weight)" </s> remove         self.adjacent[neighbor] = weight
 </s> add         if neighbor is None:
            raise Exception('Invalid neighbor')
        neighbor.incoming_edges += 1
        self.adj_weights[neighbor.key] = weight
        self.adj_nodes[neighbor.key] = neighbor

    def remove_neighbor(self, neighbor):
        if neighbor is None:
            raise Exception('Invalid neighbor')
        if neighbor.key in self.adj_nodes:
            neighbor.incoming_edges -= 1
            del self.adj_weights[neighbor.key]
            del self.adj_nodes[neighbor.key]
        else:
            raise Exception('Invalid neighbor') </s> remove     "        # TODO: Implement me\n",
    "        self.nodes = {}  # key = node id, val = node\n",
 </s> add     "        self.nodes = {}  # Key = key, val = Node\n", </s> remove         self.adjacent = {}  # key = node, val = weight
 </s> add         self.incoming_edges = 0
        self.adj_nodes = {}  # Key = key, val = Node
        self.adj_weights = {}  # Key = key, val = weight </s> remove     "* If the source node is not in the list of nodes, add it\n",
    "* If the dest node is not in the list of nodes, add it\n",
 </s> add     "* If the source node is not in the collection of nodes, add it\n",
    "* If the dest node is not in the collection of nodes, add it\n",
  
  class Graph:
  
      def __init__(self):

















keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace
 Rework graph challenge and solution (#90) 
graphs_trees/graph/graph.py