Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

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

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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)

Python: def Single_Source_Shortest_Path(adj_mat, cost, parent):
    N = len(cost)
    color = ["W" for n in range(N)]
    parent[0] = -1
    cost[0] = 0

    while True:
        mincost = 1000000

        for i in range(N):
            if color[i] != "B" and cost[i] < mincost:
                u = i
                mincost = cost[u]

        if mincost == 1000000:
            break

        color[u] = "B"

        for v in range(N):
            if color[v] != "B" and adj_mat[u][v] >= 0:
                if cost[v] > cost[u] + adj_mat[u][v]:
                    cost[v] = cost[u] + adj_mat[u][v]
                    parent[v] = u
                    color[v] = "G"

def Main():
    N = int(input())
    cost = [1000000 for n in range(N)]
    color = ["W" for n in range(N)]
    adj_mat = [[ -1 for n in range(N)] for n in range(N)]
    parent = [-1 for n in range(N)]

    for n in range(N):
        u, K, *p = map(int, input().split())

        for k in range(K):
            v, c = p[2*k], p[2*k + 1]
            adj_mat[u][v] = c

    Single_Source_Shortest_Path(adj_mat, cost, parent)

    for i in range(N):
        print("{} {}".format(i, cost[i]))

Main()