# -*- coding:utf-8 -*-


class UndirectedGraph(object):


    def __init__(self, vertex_num):
        self.v_num = vertex_num
        self.adj_table = []
        for i in range(self.v_num + 1):
            self.adj_table.append([])

    def add_edge(self, s, t):
        if s > self.v_num or t > self.v_num:
            return False
        self.adj_table[s].append(t)
        self.adj_table[t].append(s)
        return True


if __name__ == '__main__':
    g = UndirectedGraph(10)
    g.add_edge(1, 9)
    g.add_edge(1, 3)
    g.add_edge(3, 2)
    g.add_edge(3, 2)
    g.add_edge(3, 2)
    g.add_edge(3, 2)
    print(g.adj_table)
        

@@ -24,31 +24,25 @@
 %0A%0Aclass Undi
-rectedG
+g
 raph(object)
@@ -131,20 +131,18 @@
 lf.adj_t
-a
 bl
-e
  = %5B%5D%0A  
@@ -201,20 +201,18 @@
 lf.adj_t
-a
 bl
-e
 .append(
@@ -334,20 +334,18 @@
 lf.adj_t
-a
 bl
-e
 %5Bs%5D.appe
@@ -368,20 +368,18 @@
 lf.adj_t
-a
 bl
-e
 %5Bt%5D.appe
@@ -406,16 +406,363 @@
  True%0A%0A%0A
+class Digraph(object):%0A%0A%0A    def __init__(self, vertex_num):%0A        self.v_num = vertex_num%0A        self.adj_tbl = %5B%5D%0A        for i in range(self.v_num + 1):%0A            self.adj_tbl.append(%5B%5D)%0A    %0A    def add_edge(self, frm, to):%0A        if frm %3E self.v_num or to %3E self.v_num:%0A            return False%0A        self.adj_tbl%5Bfrm%5D.append(to)%0A%0A%0A%0A%0A
 if __nam
@@ -788,16 +788,17 @@
     
+u
 g = Undi
 rect
@@ -797,15 +797,9 @@
 Undi
-rectedG
+g
 raph
@@ -803,24 +803,25 @@
 aph(10)%0A    
+u
 g.add_edge(1
@@ -825,24 +825,25 @@
 e(1, 9)%0A    
+u
 g.add_edge(1
@@ -847,24 +847,25 @@
 e(1, 3)%0A    
+u
 g.add_edge(3
@@ -865,32 +865,81 @@
 _edge(3, 2)%0A    
+print(ug.adj_tbl)%0A    %0A    dg = Digraph(10)%0A    d
 g.add_edge(3, 2)
@@ -929,34 +929,35 @@
 dg.add_edge(
-3, 2
+1, 9
 )%0A    
+d
 g.add_edge(3
@@ -955,26 +955,27 @@
 dd_edge(
-3, 2
+1, 3
 )%0A    
+d
 g.add_ed
@@ -972,33 +972,33 @@
  dg.add_edge(3, 
-2
+4
 )%0A    print(g.ad
@@ -997,26 +997,16 @@
 int(
+d
 g.adj_t
-a
 bl
-e
 )%0A
-        %0A

Implement directed graph using adjacency table