import heapq

def dijkstra(adj, source):
    dist = [float('inf')] * len(adj)
    dist[source] = 0
    heap = [(0, source)]
    while heap:
        distance, u = heapq.heappop(heap)
        if distance != dist[u]:
            continue
        for v, weight in adj[u]:
            candidate = distance + weight
            if candidate < dist[v]:
                dist[v] = candidate
                heapq.heappush(heap, (candidate, v))
    return [None if value == float('inf') else value for value in dist]
