# Directed graph class, inspired by the corresponding Java class in
# Algorithms, 4th ed. by Sedgewick & Wayne, available at
# https://algs4.cs.princeton.edu/home/
#
# Jesper Larsson, Malmö University, 2018–2020

from random import randrange
from clo_decorators import clo_method, clo_property

class Digraph:
    def __init__(self, V):
        E = 0
        adj = [[] for _ in range(V)]

        @clo_method(self)
        def addedge(v, w):
            nonlocal E
            E += 1
            adj[v].append(w)

        @clo_property(self, 'V')
        def _():
            return V

        @clo_property(self, 'E')
        def _():
            return E

        @clo_method(self, 'adj')
        def _(v):
            return adj[v]

    
