Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type DirectedGraphNodeID int

type DirectedGraphNode struct {
	key         DirectedGraphNodeID
	adjacents   []*DirectedGraphNode
	costs       []int
	distance    int
	predecessor *DirectedGraphNode
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for i := 0; i < nNodes; i++ {
		node := DirectedGraphNode{}
		node.key = DirectedGraphNodeID(i)
		node.distance = infty
		graph.nodes[i] = &node
	}
	return &graph
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(i, j DirectedGraphNodeID, cost int) {
	g.nodes[i].adjacents = append(g.nodes[i].adjacents, g.nodes[j])
	g.nodes[i].costs = append(g.nodes[i].costs, cost)
}

func (g *DirectedGraph) print() {
	for i := 0; i < len(g.nodes); i++ {
		node := g.nodes[i]
		key := node.key
		strings := []string{strconv.Itoa(int(key)), strconv.Itoa(node.distance)}
		for j := 0; j < len(node.adjacents); j++ {
			nodeJ := fmt.Sprintf("(%v, %v)", node.adjacents[j].key, node.costs[j])
			strings = append(strings, nodeJ)
		}
		fmt.Printf("%v\n", strings)
	}
}

func (g *DirectedGraph) relaxEdge(l, r *DirectedGraphNode, w int) {
	if r.distance > l.distance+w {
		// fmt.Printf("%v -> %v, %v\n", l.key, r.key, l.distance+w)
		r.distance = l.distance + w
		r.predecessor = l
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	graph := newDirectedGraph(nNodes)

	for i := 0; i < nNodes; i++ {
		iNode := DirectedGraphNodeID(nextInt())
		nAdjacent := nextInt()
		for j := 0; j < nAdjacent; j++ {
			jNode := DirectedGraphNodeID(nextInt())
			cost := nextInt()
			graph.setAdjacency(iNode, jNode, cost)
		}
	}

	graph.nodes[0].distance = 0
	for iNode := 0; iNode < nNodes; iNode++ {
		for iLeft := 0; iLeft < len(graph.nodes); iLeft++ {
			nodeLeft := graph.nodes[iLeft]
			for iRight := 0; iRight < len(nodeLeft.adjacents); iRight++ {
				nodeRight := nodeLeft.adjacents[iRight]
				cost := nodeLeft.costs[iRight]
				graph.relaxEdge(nodeLeft, nodeRight, cost)
			}
		}
	}

	// graph.print()

	for iNode := 0; iNode < len(graph.nodes); iNode++ {
		node := graph.nodes[iNode]
		fmt.Println(node.key, node.distance)
	}
}

C++: #include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define RREP(i, a, b) for(int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9+7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ld PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;

template<typename T>
struct Dijkstra{
	struct edge{
		int to;
		T cost;
	};
	const T INF;
	vector<vector<edge>> g;
	vector<T> min_cost;
	
	Dijkstra(int n) : INF(numeric_limits<T>::max()){
		g.resize(n);
	}
	
	void add_edge(int from, int to, T cost){
		g[from].push_back(edge{to, cost});
	}
	
	vector<T> dijkstra(int s){
		min_cost.assign(g.size(), INF); min_cost[s] = 0;
		pq<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> qu;
		qu.push({0, s});
		
		while(!qu.empty()){
			auto p = qu.top(); qu.pop();
			
			for(auto e:g[p.second]){
				if(p.first + e.cost >= min_cost[e.to]) continue;
				min_cost[e.to] = p.first + e.cost;
				qu.push({min_cost[e.to], e.to});
			}
		}
		
		return min_cost;
	}
};


int main(){
	int n; cin >> n;
	Dijkstra<ll> dijk(n);
	for(int i = 0; i < n; i++){
		int k; cin >> k >> k;
		
		for(int j = 0; j < k; j++){
			int a, b; cin >> a >> b;
			dijk.add_edge(i, a, (ll)b);
			dijk.add_edge(a, i, (ll)b);
		}
	}
	
	vector<ll> min_cost = dijk.dijkstra(0);
	for(int i = 0; i < n; i++) cout << i << " " << min_cost[i] << endl;
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=109;
int map1[maxn][maxn];
int flag[maxn];
int vis[maxn];
int c[maxn];

void spfa(int u,int n){
    queue<int>q;
    memset(flag,0,sizeof(flag));
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
        vis[i]=inf;
    vis[0]=0;c[0]=1,flag[0]=1;
    q.push(0);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        flag[now]=0;
        for(int i=0;i<n;i++){
            if(vis[i]>vis[now]+map1[now][i]){
                vis[i]=vis[now]+map1[now][i];
                if(!flag[i]){
                    flag[i]=1;
                    q.push(i);
                }

            }
        }
    }
}

int main(){
    int n,u,v,w,k;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(i==j)
                    map1[i][j]=0;
                else
                    map1[i][j]=inf;
        for(int i=0;i<n;i++){
            scanf("%d%d",&u,&k);
            for(int j=0;j<k;j++){
                scanf("%d%d",&v,&w);
                if(map1[u][v]>w)
                    map1[u][v]=w;
            }
        }
        spfa(0,n);
        for(int i=0;i<n;i++)
            printf("%d %d\n",i,vis[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define INF 1<<30
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int V; cin >> V;
	vector<vector<pair<int, int>>> g(V);
	vector<int> dp(V);
	queue<int> q;

	//input
	for (int i = 0; i < V; i++) {
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int c, v;
			cin >> c >> v;
			g[u].push_back(make_pair(c, v));
		}
	}

	//initialize
	fill(dp.begin(), dp.end(), INF);
	dp[0] = 0;
	q.push(0);

	//Dijkstra
	while (!q.empty()) {
		int k = q.front(); q.pop();
		for (int i = 0; i < g[k].size();i++) {
			int next = g[k][i].first;
			int w = g[k][i].second;
			if (dp[k] + w < dp[next]) {
				dp[next] = dp[k] + w;
				q.push(next);
			}
		}
	}

	//output
	for (int i = 0; i < V;i++) {
		cout << i << " " << dp[i] << endl;
	}
}