In [1]:
class Graph():
def __init__(self, size):
self.data = []
for i in xrange(size):
self.data.append([])
def addEdge(self, u, v):
self.data[u].append(v)
def sum_of_dependencies(self):
count = 0
for i in self.data:
count += len(i)
return count
In [2]:
g = Graph(4)
print g.data
In [3]:
g.addEdge(0, 2)
g.addEdge(0, 3)
g.addEdge(1, 3)
g.addEdge(2, 2)
print g.data
In [4]:
print g.sum_of_dependencies()