Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
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 = j
	pq[j].index = i
}

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
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

Python: def relax(u, v, w):
    if D[u] + w < D[v]:
        D[v] = D[u] + w
        P[v] = u

INF = float('inf')
N = int(input())
D = [INF for i in range(N)]
P = [None for i in range(N)]
C = ['w' for i in range(N)]
D[0] = 0

G = [[INF for j in range(N)] for i in range(N)]
for i in range(N):
    x = list(map(int, input().split()))
    g = x[2:]
    for j, n in enumerate(g):
        if j % 2 == 0:
            G[i][n] = g[j + 1]


while True:
    mincost = INF
    u = -1
    for i in range(N):
        if C[i] != 'b' and D[i] < mincost:
            mincost = D[i]
            u = i
    if u == -1:
        break
    C[u] = 'b'
    for v, w in enumerate(G[u]):
        if w != INF and C[v] != 'b':
            relax(u, v, w)
            C[v] = 'g'

for i, d in enumerate(D):
    print('{0} {1}'.format(i, d))

Python: from heapq import heappush, heappop
from collections import deque

def main():
    INF = float('inf')
    V = int(input())
    dist = [INF] * V
    visited = [False] * V
    graph = [None] + [deque() for i in range(V-1)]
    
    q = []
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]): heappush(q, (tmp[2+2*i+1], tmp[2+2*i]))
        
    for i in range(1, V):
        tmp = list(map(int, input().split()))
        
        for j in range(tmp[1]):
            graph[i].append((tmp[2+2*j+1], tmp[2+2*j]))
        
    dist[0], visited[0] = 0, True
        
    while q:
        cost, v = heappop(q)
        if visited[v]: continue
    
        visited[v] = True
        dist[v] = cost
        
        for c, u in graph[v]:
            if visited[u] or dist[u] < cost + c: continue
            heappush(q, (cost+c, u))
    
    for i in range(V): print(i, dist[i])
        
if __name__ == '__main__':
    main()

Python: n = int(input())
g = [[2**64]*n for i in range(n)]
for i in range(n):
    u, k, *l, = map(int, input().split())
    for j in range(k):
        v, c = l[j*2], l[j*2+1]
        g[u][v] = c

'''
ダイクストラ法による単一始点最短経路
'''
d = [2**64]*n
d[0] = 0

s = []
v = [i for i in range(n)]
while len(s) < n:
    c, u = 2**32, -1
    for vv in v:
        if d[vv] < c:
            c, u = d[vv], vv
    s.append(u)
    v.remove(u)
    for i, c in enumerate(g[u]):
        if i in v and d[u]+g[u][i] < d[i]:
            d[i] = d[u]+g[u][i]

for i in range(n):
    print(f"{i} {d[i]}")

Python: 
def dijkstra(adj_matrix, n):
    dist = [float("inf") for _ in range(n)]
    visited = [False for _ in range(n)]
    parent = [-1 for _ in range(n)]

    start = 0
    dist[start] = 0
    visited[start] = True
    while True:
        for end in range(n):
            # startから出ているノードの距離を計算
            if not visited[end] and adj_matrix[start][end] > -1 and dist[start] + adj_matrix[start][end] < dist[end]:
                dist[end] = dist[start] + adj_matrix[start][end]
                parent[end] = start

        # 一番近い距離にあるノードを訪問する
        min_cost = float("inf")
        for nextnode in range(n):

            if not visited[nextnode] and dist[nextnode] < min_cost:
                min_cost = dist[nextnode]
                start = nextnode
        if min_cost == float("inf"):
            return parent, dist
        visited[start] = True


def main():
    n = int(input())
    adj_matrix = []
    for _ in range(n):
        row = [-1 for _ in range(n)]
        line = input().split()
        dim = int(line[1])
        for i in range(dim):
            row[int(line[2 + i * 2])] = int(line[2 + i * 2 + 1])
        adj_matrix.append(row)
    _, dist = dijkstra(adj_matrix, n)
    for i in range(n):
        print("{} {}".format(i, dist[i]))


if __name__ == "__main__":
    main()

Python: def diikstraMethd(G, s):
    # ?????????
    n = len(G)
    # White:0 Gyay:1 Black:2
    color = [0 for _ in range(n)]
    d = [INF for _ in range(n)]
    p = [None for _ in range(n)]

    d[s] = 0

    while True:
        mincost = INF
        for i in range(n):
            if color[i] != 2 and d[i] < mincost:
                mincost = d[i]
                u = i

        if mincost == INF: break

        color[u] = 2

        for v in range(n):
            if color[v] != 2 and M[u][v] != INF:
                if d[u] + M[u][v] < d[v]:
                    d[v] = d[u] + M[u][v]
                    p[v] = u
                    color[u] = 1

    return d

if __name__ == '__main__':
    n = int(input())
    M = [[INF for _ in range(n)] for i in range(n)]
    for _ in range(n):
        tmp = list(map(int, input().split()))
        u = tmp.pop(0)
        k = tmp.pop(0)
        for _ in range(k):
            v = tmp.pop(0)
            c = tmp.pop(0)
            M[u][v] = c
    d = diikstraMethd(M, 0)


    for i in range(n):
        print('{0} {1}'.format(i, d[i]))

Python: def shortest_path(V,uvc,start=0):
    distances = [INF]*V
    distances[start] = 0
    parents = list(range(V))

    for _ in range(V):
        modified = False
        for src,dst,cost in uvc:
            if distances[dst] > distances[src] + cost:
                distances[dst] = distances[src] + cost
                parents[dst] = src
                modified = True
        if modified == False:
            return distances,parents
    return None,None
import sys
INF = float("inf")
N = int(sys.stdin.readline())
G = tuple(tuple(map(int,sys.stdin.readline().rstrip().split()))[2:] for _ in range(N))
uvc = []
for i in range(N):
    for j in range(0,len(G[i]),2):
        uvc.append([i,G[i][j],G[i][j+1]])  
a,_ = shortest_path(N,uvc,0)
for i,v in enumerate(a):
    print(i,v)