2017-06-22 21:53:33 +00:00
|
|
|
class Graph:
|
|
|
|
def __init__(self, vertex):
|
|
|
|
self.vertex = vertex
|
|
|
|
self.graph = [[0] for i in range(vertex)]
|
|
|
|
|
|
|
|
def add_edge(self, u, v):
|
|
|
|
self.graph[u - 1].append(v - 1)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
for i in range(self.vertex):
|
|
|
|
print('%d: '% (i + 1), end=' ')
|
|
|
|
for j in self.graph[i]:
|
|
|
|
print('%d-> '% (j + 1), end=' ')
|
|
|
|
print(' ')
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-27 11:20:28 +00:00
|
|
|
g = Graph(100)
|
2017-06-22 21:53:33 +00:00
|
|
|
|
2017-08-28 13:25:52 +00:00
|
|
|
g.add_edge(1,3)
|
2017-06-22 21:53:33 +00:00
|
|
|
g.add_edge(2,3)
|
|
|
|
g.add_edge(3,4)
|
|
|
|
g.add_edge(3,5)
|
2017-08-28 13:25:52 +00:00
|
|
|
g.add_edge(4,5)
|
|
|
|
|
2017-06-22 21:53:33 +00:00
|
|
|
|
|
|
|
g.show()
|
|
|
|
|