Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

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

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

Python: from sys import stdin
from collections import defaultdict
from heapq import heappush, heappop
import math

n = int(input())
g = defaultdict(list)

for i in range(n):
    l = list(map(int, stdin.readline().split()))
    s = l[0]
    k = l[1]
    t = l[2:]
    for j in range(0, 2*k, 2):
        g[s].append((t[j+1], t[j]))

d = [float('inf')] * 100
d[0] = 0
heap = [(d[0], 0)]

while heap:

    du, u = heappop(heap)
    for length, v in g[u]:

        if d[v] > du + length:
            d[v] = du + length
            heappush(heap, (d[v], v))

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

Python: # -*- coding: utf-8 -*-
"""
Created on Sat Jul 14 19:11:44 2018

@author: maezawa
"""
infinity = 2*10**9

n = int(input())
adj = [[] for _ in range(n)]

for j in range(n):
    ain = list(map(int, input().split()))
    u = ain[0]
    k = ain[1]
    for i in range(2,2+2*k,2):
        adj[u].append([ain[i],ain[i+1]])
    #print(*adj[u])

color = [0]*n
d = [infinity for _ in range(n)]
p = [0]*n
p[0] = -1
d[0] = 0

def dyk(s):
    cnt = 1
    cur = s
    candidates = [] # remaining nodes
    while True:
        for i, w in adj[cur]:
            if color[i] == 2:
                continue
            if d[i] > d[cur] + w:
                d[i] = d[cur] + w
                color[i] = 1
            candidates.append(i)
        min_d = infinity
        for j in candidates:
            if min_d > d[j]:
                min_node = j
                min_d = d[j]
        candidates.remove(min_node)
        p[min_node] = cur
        color[cur] = 2
        cur = min_node
        cnt += 1
        #print(cur, d)
        if cnt == n:
            break
    return

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

Python: from collections import defaultdict

n = int(input())
graph = defaultdict(list)
for _ in range(n):
    u, k, *edges = map(int, input().split())
    for i in range(0, len(edges), 2):
        graph[u].append((edges[i], edges[i+1]))

# print(graph)

s = 0
d = [float('inf')] * (n)
fixed = [False] * (n)
d[0] = 0

while True:
    u = None
    d_min = float('inf')
    for i in range(len(d)):
        if not fixed[i] and d[i] < d_min:
            d_min = d[i]
            u = i

    if u is None:
        break            
    fixed[u] = True
    # print('fixed:', u)

    for v, w in graph[u]:
        if not fixed[v]:
            d[v] = min(d[v], d[u]+w)
    # print(d)

# print(d)

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

Python: n = int(input())

adj = [[100001 for j in range(n)] for i in range(n)]

for u in range(n):
    x = list(map(int, input().split()))
    for v, c in zip(x[2::2], x[3::2]):
        adj[u][v] = c

isVisited = [False] * n

distance = [9900001] * n


def dijkstra(s):
    distance[s] = 0

    while True:
        mincost = 9900001
        for i in range(n):
            if (not isVisited[i]) and (distance[i] < mincost):
                mincost = distance[i]
                u = i

        if mincost == 9900001:
            break

        isVisited[u] = True

        for v in range(n):
            weight_uv = adj[u][v]
            if (not isVisited[v]) and (weight_uv != 100001):
                t_d = distance[u] + weight_uv
                if t_d < distance[v]:
                    distance[v] = t_d



dijkstra(0)

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

Python: #coding:utf-8
def Dijkestra(G,n):
    d=[100000000000]*n
    pi=[None]*n
    d[0]=0
    C=[]
    for i in range(n):
        C.append(i)
    
    while len(C)!=0:
        u=C[0]
        for i in range(1,len(C)):
            if d[u]>d[i]:
                u=i
        C.remove(u)
        for i in range(len(G[u])):
            if G[u][i]==-1:
                continue
            elif d[i]>d[u]+G[u][i]:
                d[i]=d[u]+G[u][i]
                pi[i]=u
                        
    for i in range(n):
        print(i,d[i])
    

if __name__=="__main__":
    n=int(input())
    G=[]
    for i in range(n):
        a=[]
        ele=list(map(int,input().split()))
        k=ele[1]
        t=ele[2:]
        v=c=[]
        for j in range(k):
            v=v+[t[2*j]]
            c=c+[t[2*j+1]]
        for j in range(n):
            if j in v:
                a.append(c[v.index(j)])
            else:
                a.append(-1)
        G.append(a)
    Dijkestra(G,n)

Python: INF = float('inf')
N = int(input())
D = [INF] * N
Visited = [False] * N
M = [[INF] * N for _ in range(N)]
for _ in range(N):
    u, k, *cv = map(int, input().split())
    for i in range(0, len(cv), 2):
        c, v = cv[i], cv[i + 1]
        M[u][c] = v

D[0] = 0

while True:
    min_cost = INF
    u = -1
    for i in range(N):
        if not Visited[i] and D[i] < min_cost:
            u = i
            min_cost = D[i]

    if u == -1:
        break

    Visited[u] = True

    for i in range(N):
        if not Visited[i] and M[u][i] != INF and M[u][i] + D[u] < D[i]:
            D[i] = M[u][i] + D[u]

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

Python: n=int(input())
M=[[-1]*n for _ in[0]*n]
for _ in[0]*n:
 e=list(map(int,input().split()))
 for i in range(e[1]):k=2*-~i;M[e[0]][e[k]]=e[k+1]
d=[0]+[1e6]*n
c=[1]*n
while 1:
 m,u=1e6,-1
 for i in range(n):
  if m>d[i]and c[i]:m,u=d[i],i
 if u<0:break
 c[u]=0
 for v in range(n):
  if c[v]and 1+M[u][v]and d[v]>d[u]+M[u][v]:
   d[v]=d[u]+M[u][v]
for i in range(n):print(i,d[i])

Python: n = int(input())

adj = [[False for j in range(n)] for i in range(n)]

for u in range(n):
    x = list(map(int, input().split()))
    for v, c in zip(x[2::2], x[3::2]):
        adj[u][v] = c

weights = [9900000] * n


def search(goal, path, weight):
    e = path[-1]
    if weight < weights[goal]:
        if e == goal:
            weights[goal] = weight
        else:
            for v, c in enumerate(adj[e]):
                if (v not in path) and (c is not False):
                    path.append(v)
                    weight += c
                    search(goal, path, weight)
                    weight -= c
                    path.pop()


for i in range(n):
    search(i, [0], 0)

for v, w in enumerate(weights):
    print(v, w)