
"""simple docstring"""

# A Bipartite Graph is a graph whose vertices can be divided into two independent sets,
# U and V such that every edge (u, v) either connects a vertex from U to V or a vertex
# from V to U. In other words, for every edge (u, v), either u belongs to U and v to V,
# or u belongs to V and v to U. We can also say that there is no edge that connects
# vertices of same set.
from queue import Queue




def       lowercase__  (   lowerCAmelCase			:   Optional[Any]	)	-> Any:






    """simple docstring"""




    UpperCAmelCase       =   Queue()
    UpperCAmelCase       =   [False] * len(lowerCAmelCase	)
    UpperCAmelCase       =   [-1] * len(lowerCAmelCase	)

    def bfs():
        while not queue.empty():
            UpperCAmelCase       =   queue.get()
            UpperCAmelCase       =   True

            for neighbour in graph[u]:
                if neighbour == u:
                    return False

                if color[neighbour] == -1:
                    UpperCAmelCase       =   1 - color[u]
                    queue.put(lowerCAmelCase	)

                elif color[neighbour] == color[u]:
                    return False

        return True

    for i in range(len(lowerCAmelCase	)	):
        if not visited[i]:
            queue.put(lowerCAmelCase	)
            UpperCAmelCase       =   0
            if bfs() is False:
                return False

    return True


if __name__ == "__main__":
   # Adjacency List of graph
   print(check_bipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]}))





"""simple docstring"""

import heapq




def       lowercase__  (   lowerCAmelCase			:   str	,			lowerCAmelCase			:   int	,			lowerCAmelCase			:   Optional[Any]	)	-> Union[str, Any]:






    """simple docstring"""




    UpperCAmelCase       =   [(0, start)]  # cost from start node,end node
    UpperCAmelCase       =   set()
    while heap:
        ((UpperCAmelCase)     ,							(UpperCAmelCase))       =   heapq.heappop(lowerCAmelCase	)
        if u in visited:
            continue
        visited.add(lowerCAmelCase	)
        if u == end:
            return cost
        for v, c in graph[u]:
            if v in visited:
                continue
            UpperCAmelCase       =   cost + c
            heapq.heappush(lowerCAmelCase	,			(next_item, v)	)
    return -1


SCREAMING_SNAKE_CASE_         =  {
    '''A''': [['''B''', 2], ['''C''', 5]],
    '''B''': [['''A''', 2], ['''D''', 3], ['''E''', 1], ['''F''', 1]],
    '''C''': [['''A''', 5], ['''F''', 3]],
    '''D''': [['''B''', 3]],
    '''E''': [['''B''', 4], ['''F''', 3]],
    '''F''': [['''C''', 3], ['''E''', 3]],
}
SCREAMING_SNAKE_CASE_         =  {
    '''B''': [['''C''', 1]],
    '''C''': [['''D''', 1]],
    '''D''': [['''F''', 1]],
    '''E''': [['''B''', 1], ['''F''', 3]],
    '''F''': [],
}
SCREAMING_SNAKE_CASE_         =  {
    '''B''': [['''C''', 1]],
    '''C''': [['''D''', 1]],
    '''D''': [['''F''', 1]],
    '''E''': [['''B''', 1], ['''G''', 2]],
    '''F''': [],
    '''G''': [['''F''', 1]],
}

SCREAMING_SNAKE_CASE_         =  dijkstra(G, '''E''', '''C''')
print(short_distance)  # E -- 3 --> F -- 3 --> C == 6

SCREAMING_SNAKE_CASE_         =  dijkstra(Ga, '''E''', '''F''')
print(short_distance)  # E -- 3 --> F == 3

SCREAMING_SNAKE_CASE_         =  dijkstra(Ga, '''E''', '''F''')
print(short_distance)  # E -- 2 --> G -- 1 --> F == 3

if __name__ == "__main__":
   import doctest

   doctest.testmod()



