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: import sys

f_i = sys.stdin

n = int(f_i.readline())

class VCost:
    def __init__(self, v, cost):
        self.v_n = v
        self.cost = cost
    def __lt__(self, other):
        return self.cost < other.cost
    def __gt__(self, other):
        return self.cost > other.cost

adj = [[VCost(int(v), int(c)) for v, c in zip(x.split()[2::2], x.split()[3::2])] for x in f_i]

import heapq

def dijkstra():
    PQ = []
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    heapq.heappush(PQ, VCost(0, 0))
    
    while PQ:
        uc = heapq.heappop(PQ)
        u = uc.v_n

        if uc.cost > distance[uc.v_n]:
            continue

        isVisited[u] = True
        
        for vc in adj[u]:
            v = vc.v_n
            if isVisited[v] == True:
                continue
            t_cost = distance[u] + vc.cost
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, VCost(v, t_cost))

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


dijkstra()

Python: import heapq


n = int(input())
M = {}
for _ in range(n):
    u, k, *line = map(int, input().split())
    tmp = []
    for i in range(k):
        v, w = line[2*i:2*i+2]
        tmp.append((v, w))
    M[u] = tmp

INF = 10**10
WHITE = 0
GREY = 1
BLACK = 2
d = [INF for i in range(n)]
d_heap = []
color = [WHITE]*n
p = [-1]*n


def dijkstra():
    d[0] = 0
    p[0] = -1
    heapq.heappush(d_heap, (0, 0))

    while len(d_heap):
        # 最も小さいnodeを持ってくる、これもheapで処理したい。
        _, u = heapq.heappop(d_heap)
        color[u] = BLACK

        # heapで距離更新
        for v, w in M[u]:
            if color[v] != BLACK:
                if d[u]+w < d[v]:
                    d[v] = d[u]+w
                    p[v] = u
                    heapq.heappush(d_heap, (d[v], v))


dijkstra()
for i in range(n):
    print(i, d[i])

Python: n = int(input())
import heapq
G = {}
for i in range(n):
    i = [int(i) for i in input().split()]
    k = i[1]
    G[i[0]] = list(zip(i[2::2],i[3::2]))

def dijkstra(G):
    d = [0] + [float('inf')] * (n - 1)
    Q = [(d[i], i) for i in range(n)]
    heapq.heapify(Q)
    while len(Q) != 0:
        _, u = heapq.heappop(Q)
        for v, c in G[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] + c
                heapq.heappush(Q, (d[v], v))
    return d

for i,j in enumerate(dijkstra(G)):
    print(i, j)

Python: import heapq

n = int(input())
G = [[] for i in range(n)]
for ni in range(n):
    u, k, *tmp = [int(i) for i in input().split()]
    for ki in range(k):
        G[ni].append(tmp[:2])
        del tmp[:2]

INF = 100*100000
D = [INF for i in range(n)]
D[0] = 0
C = [0 for i in range(n)]
U = []
u = 0
while 0 in C:
    i = 0
    while U != []:
        u = heapq.heappop(U)[1]
        if C[u] == 0:
            break

    for i in range(len(G[u])):
        v = G[u][i][0]
        if D[u] + G[u][i][1] < D[v]:
            D[v] = D[u] + G[u][i][1]
            heapq.heappush(U, [D[v], v])
    C[u] = 1

for ni in range(n):
    print(ni, D[ni])

Python: import sys

f_i = sys.stdin

n = int(f_i.readline())

adj = [[]] * n
for x in f_i:
    x = list(map(int, x.split()))
    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]

import heapq

def dijkstra():
    PQ = [(0, 0)]
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    
    while PQ:
        uc, u = heapq.heappop(PQ)

        if uc > distance[u]:
            continue

        isVisited[u] = True
        
        for vc, v in adj[u]:
            if isVisited[v] == False:
                t_cost = distance[u] + vc
                if t_cost < distance[v]:
                    distance[v] = t_cost
                    heapq.heappush(PQ, (t_cost, v))

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


dijkstra()

Python: n = int(input())
G = [[[], []] for j in range(n)]
d = [999999 for i in range(n)]
  
for i in range(n):
    v = input().split()
    for j in range(int(v[1])):
        G[int(v[0])][0].append(int(v[2+2*j]))
        G[int(v[0])][1].append(int(v[3+2*j]))

d = [999999] * n
flag = [0] * n
d[0] = 0
while True:
    v = -1
    for j in range(n):
        if flag[j] != 1 and (v == -1 or d[j] < d[v]):
            v = j
    if v == -1:
        break
    flag[v] = 1
    for j in range(n):
        if j not in G[v][0]: continue
        i = 0
        while True:
            if G[v][0][i] == j:
                d[j] = min(d[j], d[v] + G[v][1][i])
                break
            i += 1

for i in range(n):
    print(str(i) + " " + str(d[i]))

Python: inf = float('inf')
n = int(input())
g = []
for i in range(n):
    line = list(map(int, input().split()[2:]))
    g.append(zip(line[0::2], line[1::2]))

distance = [inf] * n
distance[0] = 0
visited = [False] * n
current = 0

while not all(visited):
    visited[current] = True
    for v, c in g[current]:
        if not visited[v] and distance[current] + c < distance[v]:
            distance[v] = distance[current] + c
    min_i = 0
    min_d = inf
    for i in range(n):
        if not visited[i] and distance[i] < min_d:
            min_i = i
            min_d = distance[i]
    current = min_i

for i in range(n):
    print(i, distance[i])