IMT.py
def subgraphStat(G,V):
    """Compute some statistics about the induced subgraph of G by V using
    an adaptation of the breadth-first search.
    
    INPUTS:
        G - a graph
        V - a subset of vertices
        
    OUTPUTS:
        l - number of leaves of the induced subgraph if it is a 
        forest, -1 if not.
        connexity_lack - A lower bound on the increase in the number of
        internal vertices required to connect the induced subgraph if it
        is a forest with value 0 iff the subforest is a tree. -1 if the
        induced subgraph is not a forest"""
    if len(V)==0:
        return 0,0

    visited=dict()
    number_of_component=0
    l=0
    for v in V:
        visited[v]=False
    while v!=None:
        #Explore a connected component
        number_of_component+=1
        Q=deque([v])
        while len(Q)>0: 
            v=Q.popleft()
            if visited[v]:
                #The subgraph is not acyclic
                return -1, -1
            visited[v]=True
            degree=0
            for son in G.neighbor_iterator(v):
                if son in V:
                    degree+=1
                    if not visited[son]:
                        Q.append(son)
            if degree==1:
                #The vertex is a leaf
                l+=1
        #Search for a new connected component
        v=None
        for s in V: 
            if not visited[s]:
                v=s
                break

    return l,int(number_of_component>1)
Compute some statistics about the induced subgraph of G by V using
    an adaptation of the breadth-first search.
    
    INPUTS:
        G - a graph
        V - a subset of vertices
        
    OUTPUTS:
        l - number of leaves of the induced subgraph if it is a 
        forest, -1 if not.
        connexity_lack - A lower bound on the increase in the number of
        internal vertices required to connect the induced subgraph if it
        is a forest with value 0 iff the subforest is a tree. -1 if the
        induced subgraph is not a forest
Compute some statistics about the induced subgraph of G by V using
an adaptation of the breadth-first search.

a graph
V - a subset of vertices

number of leaves of the induced subgraph if it is a
forest, -1 if not.
connexity_lack - A lower bound on the increase in the number of
internal vertices required to connect the induced subgraph if it
is a forest with value 0 iff the subforest is a tree. -1 if the
induced subgraph is not a forest
Compute some statistics about the induced subgraph of G by V using an adaptation of the breadth - first search . a graph V - a subset of vertices number of leaves of the induced subgraph if it is a forest - 1 if not . connexity_lack - A lower bound on the increase in the number of internal vertices required to connect the induced subgraph if it is a forest with value 0 iff the subforest is a tree . - 1 if the induced subgraph is not a forest
def subgraphStat(G,V):
    if len(V)==0:
        return 0,0
    visited=dict()
    number_of_component=0
    l=0
    for v in V:
        visited[v]=False
    while v!=None:
        number_of_component+=1
        Q=deque([v])
        while len(Q)>0: 
            v=Q.popleft()
            if visited[v]:
                return -1, -1
            visited[v]=True
            degree=0
            for son in G.neighbor_iterator(v):
                if son in V:
                    degree+=1
                    if not visited[son]:
                        Q.append(son)
            if degree==1:
                l+=1
        v=None
        for s in V: 
            if not visited[s]:
                v=s
                break
    return l,int(number_of_component>1)
def subgraphStat ( G , V ) : if len ( V ) == 0 : return 0 , 0 visited = dict ( ) number_of_component = 0 l = 0 for v in V : visited [ v ] = False while v != None : number_of_component += 1 Q = deque ( [ v ] ) while len ( Q ) > 0 : v = Q . popleft ( ) if visited [ v ] : return - 1 , - 1 visited [ v ] = True degree = 0 for son in G . neighbor_iterator ( v ) : if son in V : degree += 1 if not visited [ son ] : Q . append ( son ) if degree == 1 : l += 1 v = None for s in V : if not visited [ s ] : v = s break return l , int ( number_of_component > 1 )
Compute some statistics about the induced subgraph of G by V using
an adaptation of the breadth-first search.
Compute some statistics about the induced subgraph of G by V using an adaptation of the breadth - first search .
"""Compute some statistics about the induced subgraph of G by V using
    an adaptation of the breadth-first search.
    
    INPUTS:
        G - a graph
        V - a subset of vertices
        
    OUTPUTS:
        l - number of leaves of the induced subgraph if it is a 
        forest, -1 if not.
        connexity_lack - A lower bound on the increase in the number of
        internal vertices required to connect the induced subgraph if it
        is a forest with value 0 iff the subforest is a tree. -1 if the
        induced subgraph is not a forest""" #Explore a connected component #The subgraph is not acyclic #The vertex is a leaf #Search for a new connected component
G
V