codeforces/580C_park.py
def calculate(self):
        """ Main calcualtion function of the class """

        result = 0

        # DFS to determine parent-child
        d = collections.deque([self.nodes[0]])
        visited = set()
        while d:
            v = d.pop()
            visited.add(v.i)
            for e in v.edges:
                if e.i not in visited:
                    v.add_child(e)
                    d.append(e)

        # DFS to calculate consecutive cats
        d = collections.deque([self.nodes[0]])
        while d:
            v = d.pop()
            v.cons = v.n if v.i == 0 else (v.parent.cons + 1 if v.n else 0)
            if v.cons <= self.m:
                d.extend(v.children)
                if not v.children:
                    result += 1

        return str(result)
 Main calcualtion function of the class 
Main calcualtion function of the class
Main calcualtion function of the class
def calculate(self):
        result = 0
        d = collections.deque([self.nodes[0]])
        visited = set()
        while d:
            v = d.pop()
            visited.add(v.i)
            for e in v.edges:
                if e.i not in visited:
                    v.add_child(e)
                    d.append(e)
        d = collections.deque([self.nodes[0]])
        while d:
            v = d.pop()
            v.cons = v.n if v.i == 0 else (v.parent.cons + 1 if v.n else 0)
            if v.cons <= self.m:
                d.extend(v.children)
                if not v.children:
                    result += 1
        return str(result)
def calculate ( self ) : result = 0 d = collections . deque ( [ self . nodes [ 0 ] ] ) visited = set ( ) while d : v = d . pop ( ) visited . add ( v . i ) for e in v . edges : if e . i not in visited : v . add_child ( e ) d . append ( e ) d = collections . deque ( [ self . nodes [ 0 ] ] ) while d : v = d . pop ( ) v . cons = v . n if v . i == 0 else ( v . parent . cons + 1 if v . n else 0 ) if v . cons <= self . m : d . extend ( v . children ) if not v . children : result += 1 return str ( result )
Main calcualtion function of the class
Main calcualtion function of the class
""" Main calcualtion function of the class """ # DFS to determine parent-child # DFS to calculate consecutive cats
self