Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

Python: from queue import PriorityQueue

def sssp(adj_list):
    n = len(adj_list)
    d = [None]*n
    pq = PriorityQueue()
    pq.put((0, 0)) # d, v

    while(not pq.empty()):
        d_v, v = pq.get()
        if d[v] is not None:
            continue
        d[v] = d_v
        for u, c_vu in adj_list[v]:
            pq.put((d[v]+c_vu, u))

    return d


if __name__ == '__main__':
    n = int(input())
    adj_list = []
    for _ in range(n):
        adj_list.append([])

    for _ in range(n):
        l = list(map(int, input().rstrip().split(' ')))
        u = l[0]
        k = l[1]
        adj_list_for_u = []
        for v, c in zip(l[2::2], l[3::2]):
            adj_list_for_u.append((v,c))
        adj_list[u] = adj_list_for_u

    d = sssp(adj_list)
    for u, d_u in zip(range(n), d):
        print (u, d_u)

Python: from collections import deque

n = int(input())
g = []
d = [10**10] * n
d[0] = 0

for i in range(n):
    temp = list(map(int, input().split()))
    k = temp[1]
    temp = temp[2:]
    adj = []
    for j in range(k):
        v, c = temp[j*2], temp[j*2+1]
        adj.append([v, c])
    g.append(adj)

# for i in range(n):
#     print(g[i])

q = deque()
q.append((0, g[0]))
done = set()

while q:
    node = q.popleft()
    prev = node[0]
    adj = node[1]
    # print('\nadj:', adj)

    for next in adj:
        v = next[0]
        w = next[1]
        # print('v:', v)
        # print('prev:', prev)

        # d[v] = min(d[v], d[prev] + w)
        if d[prev] + w < d[v]:
            d[v] = d[prev] + w
            # Need to add to Q regardless of it's in done or not,
            # because the shortest path was udpated.
            q.append((v, g[v]))
        if v not in done:
            done.add(v)
            q.append((v, g[v]))

# print('d:', d)

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

Python: n = int(input())
edgeList = []
rootList = [-1 for i in range(n)]
parent = [-1 for i in range(n)]
lenList = [0 for i in range(n)]
sumLength = 0
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(a[1]):
        edgeList.append([a[2*j+3], i, a[2*j+2]])


rootList = [-1 for i in range(n)]
parent = [0 for i in range(n)]
lenList = [float("inf") for i in range(n)]
lenList[0] = 0
def getRoot(x):
    r = rootList[x]
    if r < 0:
        rootList[x] = x
    elif r != x:
        rootList[x] = getRoot(r)
    return rootList[x]

flag = True
while flag:
    flag = False
    edgeList.sort(key=lambda x: (x[0] + lenList[x[1]]))
    for e in edgeList:    # weight:e[0], e[1]->e[2]
        if e[2] == 0:
            continue
        x = getRoot(e[1])
        y = getRoot(e[2])
        if x == 0 != y:
            parent[e[2]] = e[1]
            lenList[e[2]] = lenList[e[1]] + e[0]
            rootList[y] = 0
            flag = True
            break

for i, j in zip(range(n), lenList):
    print(i, j)

Python: n=int(input())
inf=10000000
p=[-1 for i in range(n)]
M=[[inf for j in range(n)] for i in range(n)]
d=[inf for i in range(n)]
color=["white" for i in range(n)]
for i in range(n):
    tmp=list(map(int,input().split()))
    root=tmp[0]
    k=tmp[1]
    for j in range(k):
        v=tmp[2*(j+1)]
        M[root][v]=tmp[2*(j+1)+1]

def dijkstra(s):
    d[s]=0
    while True:
        mincost=inf
        for i in range(n):
            if color[i] is not "black" and d[i]<mincost:
                mincost=d[i]
                u=i
        if mincost is inf:
            break
        color[u]="black"
        for j in range(n):
            if color[j] is not "black" and M[u][j] is not inf:
                if d[u]+M[u][j]<d[j]:
                    d[j]=d[u]+M[u][j]
                    color[j]="gray"
                    p[j]=u

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

Python: trial = int(input())
graph = []
for t in range(trial):
    graph.append([int(n) for n in input().split(" ")])
root = []
ans = []
stack = [[0,0]]
cnt = 0
while len(stack) > 0:
    index,out = stack[0][0],stack[0][1]
    print(index,out,stack,graph)
    for get in range(graph[index][1]):
        if graph[index][get*2 + 2] not in root:
            stack.append([graph[index][get*2 +2],graph[index][get*2 +3] + out ])
    if stack[0][0] not in root:
        root.append(stack[0][0])
        ans.append([stack[0][0],stack[0][1]])
    stack.pop(0)
    stack = sorted(stack,key=lambda x:x[1])
ans = sorted(ans,key=lambda x:x[0])
for a in ans:
    print(a)

Python: #!/usr/bin/python3
n = int(input())
inf = 100 * 100000

M = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    L = list(map(int, input().split()))
    u = L[0]
    k = L[1]
    v = L[2::2]
    c = L[3::2]
    for j in range(k):
        M[u][v[j]] = M[v[j]][u] = c[j]

S = set()
V = set(range(n))
S.add(0)
d = [inf for i in range(n)]
d[0] = 0
count = 0
while len(V - S) != 0 and count < 10:
    T = V - S
    nd = [inf for i in range(n)]
    for s in S:
        for m, c in enumerate(M[s]):
            if d[s] + c < nd[m] and m in T:
                nd[m] = d[s] + c

    min_nd = min(nd)
    u = nd.index(min_nd)
    S.add(u)
    d[u] = min_nd

    count += 1

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