dist = [inf] * (n+1)
dist[src] = 0
q = deque()
q.append(src)
visited = set()
visited.add(src)
while q:
    u = q.popleft()
    visited.remove(u)

    for v, d in adj[u]:
        if dist[u] + d < dist[v]:
            if v not in visited:
                q.append(v)
                visited.add(v)
            dist[v] = dist[u] + d