Go: package main

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

const (
	MAX_N      = 100
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

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

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{1}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd()-1, v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 1
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node-1]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node-1] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode-1]
	edges := []Edge{}
	for i, v := range adjacents {
		if v > 0 {
			edges = append(edges, Edge{start: currentNode, end: i + 1, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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()