(self)
Reduces the higher-order network to its 
        largest (giant) strongly connected component 
        (using Tarjan's algorithm)
Reduces the higher-order network to its 
        largest (giant) strongly connected component 
        (using Tarjan's algorithm)
Reduces the higher - order network to its largest ( giant ) strongly connected component ( using Tarjan s algorithm )
def reduceToGCC(self):
        """ 
        Reduces the higher-order network to its 
        largest (giant) strongly connected component 
        (using Tarjan's algorithm)
        """

        # nonlocal variables (!)        
        index = 0
        S = []
        indices = _co.defaultdict( lambda: None )
        lowlink = _co.defaultdict( lambda: None )        
        onstack = _co.defaultdict( lambda: False )

        # Tarjan's algorithm
        def strong_connect(v):
            nonlocal index
            nonlocal S
            nonlocal indices
            nonlocal lowlink            
            nonlocal onstack
                        
            indices[v] = index
            lowlink[v] = index
            index += 1
            S.append(v)
            onstack[v] = True

            for w in self.successors[v]:
                if indices[w] == None:
                    strong_connect(w)
                    lowlink[v] = min(lowlink[v], lowlink[w])
                elif onstack[w]:
                    lowlink[v] = min(lowlink[v], indices[w])
            
            # Generate SCC of node v
            component = set()
            if lowlink[v] == indices[v]:
                while True:
                    w = S.pop()
                    onstack[w] = False
                    component.add(w)
                    if v==w:
                        break
            return component

        # Get largest strongly connected component 
        components = _co.defaultdict( lambda: set() )
        max_size = 0
        max_head = None
        for v in self.nodes:
            if indices[v] == None:
                components[v] = strong_connect(v)
                if len(components[v]) > max_size:
                    max_head = v
                    max_size = len(components[v])
        
        scc = components[max_head]

        # Reduce higher-order network to SCC
        for v in list(self.nodes):
            if v not in scc:
                self.nodes.remove(v)
                del self.successors[v]

        for (v,w) in list(self.edges):
            if v not in scc or w not in scc:
                del self.edges[(v,w)]
def reduceToGCC ( self ) : # nonlocal variables (!)         index = 0 S = [ ] indices = _co . defaultdict ( lambda : None ) lowlink = _co . defaultdict ( lambda : None ) onstack = _co . defaultdict ( lambda : False ) # Tarjan's algorithm def strong_connect ( v ) : nonlocal index nonlocal S nonlocal indices nonlocal lowlink nonlocal onstack indices [ v ] = index lowlink [ v ] = index index += 1 S . append ( v ) onstack [ v ] = True for w in self . successors [ v ] : if indices [ w ] == None : strong_connect ( w ) lowlink [ v ] = min ( lowlink [ v ] , lowlink [ w ] ) elif onstack [ w ] : lowlink [ v ] = min ( lowlink [ v ] , indices [ w ] ) # Generate SCC of node v component = set ( ) if lowlink [ v ] == indices [ v ] : while True : w = S . pop ( ) onstack [ w ] = False component . add ( w ) if v == w : break return component # Get largest strongly connected component  components = _co . defaultdict ( lambda : set ( ) ) max_size = 0 max_head = None for v in self . nodes : if indices [ v ] == None : components [ v ] = strong_connect ( v ) if len ( components [ v ] ) > max_size : max_head = v max_size = len ( components [ v ] ) scc = components [ max_head ] # Reduce higher-order network to SCC for v in list ( self . nodes ) : if v not in scc : self . nodes . remove ( v ) del self . successors [ v ] for ( v , w ) in list ( self . edges ) : if v not in scc or w not in scc : del self . edges [ ( v , w ) ]