Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

Python: inf = float("inf")
n = int(input())
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
    L = list(map(int, input().split()))
    for j in range(L[1]):
        M[L[0]][L[2 * j + 2]] = L[2 * j + 3]


def dijkstra(s):
    color = [0] * n
    d = [inf] * n
    d[s] = 0

    while True:
        mincost = inf
        for i in range(n):
            if color[i] !=1 and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == inf: break
        color[u] = 1
        for v in range(n):
            if color[v] != 1 and M[u][v] != inf:
                if d[u] + M[u][v] < d[v]:
                    d[v] = d[u] + M[u][v]

    return d

d = dijkstra(0)
for i,v in enumerate(d):
 print("{} {}".format(i,v))

Python: class Graph:
    def __init__(self,V,E):
        self.V = V
        self.E = E

    def WF(self,st):
        N,INF = len(self.V),10**7+1
        dp = [INF for _ in range(N)]
        #dp[i]:頂点stから頂点iへの最小距離
        dp[st] = 0
        update = True
        while update:
            update = False
            for i in range(N):
                for j in range(N):
                    if (j,i) in self.E:
                        if dp[i] > dp[j] + self.E[(j,i)]:
                            dp[i] = dp[j] + self.E[(j,i)]
                            update = True
        return dp

def main():
    n = int(input())
    I = [list(map(int,input().split())) for _ in range(n)]
    V = set([i for i in range(n)])
    E = {}
    for i in range(n):
        for j in range(I[i][1]):
            E[(I[i][0],I[i][j*2+2])] = I[i][j*2+3]
    G = Graph(V,E)
    sp = G.WF(0)
    for i in range(n):
        print(i,sp[i])

if __name__ == "__main__":
    main()

Python: from heapq import heappush, heappop
from typing import List, Tuple
import sys


if __name__ == "__main__":
    num_vertices = int(input())
    adj_list: List[List[Tuple[int, int]]] = [[] for _ in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, adj_num, *adjs = map(lambda x: int(x), input().split())
        for i in range(adj_num):
            # (cost, adj)
            adj_list[vertex].append((adjs[2 * i + 1], adjs[2 * i]))

    distances: List[int] = [sys.maxsize] * num_vertices
    distances[0] = 0
    que: List[Tuple[int, int]] = []
    heappush(que, (0, 0))

    while [] != que:
        base_distance, parent = heappop(que)
        for cost, adj in adj_list[parent]:
            distance = base_distance + cost
            if distance < distances[adj]:
                distances[adj] = distance
                heappush(que, (distance, adj))

    for vertex, distance in enumerate(distances):
        print(f"{vertex} {distance}")

Python: import heapq

class Dijkstra:
    """
        Dijkstra's algorithm: find the shortest paths from a vertex
        complexity:
            O(E + logV)
    """
    def __init__(self, V, E, start, INF=10**9):
        """
        :param V: the number of vertices
        :param E: adjacency list (all edge in E must be non negative)
        :param start: start vertex
        :param INF: Infinity distance
        """
        self.V = V
        self.E = E
        self.dijkstra(start, INF)

    def dijkstra(self, start, INF):
        que = list()
        self.distance = [INF] * self.V
        self.prev = [-1] * self.V
        self.distance[start] = 0
        heapq.heappush(que, (0, start))
        while len(que) > 0:
            dist, fr = heapq.heappop(que)
            if self.distance[fr] < dist:
                continue
            for to, cost in self.E[fr]:
                if self.distance[fr] + cost < self.distance[to]:
                    self.distance[to] = self.distance[fr] + cost
                    heapq.heappush(que, (self.distance[to], to))
                    self.prev[to] = fr

    def get_path(self, end):
        path = [end]
        while self.prev[end] != -1:
            end = self.prev[end]
            path.append(end)
            return path[::-1]


V = int(input())
edges = [[] for _ in range(V)]
for _ in range(V):
    u, _, *e = map(int, input().split())
    for t, d in zip(e[::2], e[1::2]):
        edges[u].append((t, d))

djk = Dijkstra(V, edges, 0)
for i, d in enumerate(djk.distance):
    print(i, d)

Python: n = int(input())

adj = [[100001 for j in range(n)] for i in range(n)]

for u in range(n):
    x = list(map(int, input().split()))
    for v, c in zip(x[2::2], x[3::2]):
        adj[u][v] = c

unvisited = [v for v in range(n)]

distance = [9900001] * n


def dijkstra(s):
    distance[s] = 0

    while True:
        mincost = 9900001
        for i in unvisited:
            if distance[i] < mincost:
                mincost = distance[i]
                u = i

        if mincost == 9900001:
            break

        unvisited.remove(u)

        for v in unvisited:
            weight_uv = adj[u][v]
            if weight_uv != 100001:
                t_d = distance[u] + weight_uv
                if t_d < distance[v]:
                    distance[v] = t_d



dijkstra(0)

for v, d in enumerate(distance):
    print(v, d)