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 <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;  //firstは最短距離,secondは頂点番号

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct edge{
	int to,cost;
	edge(){to=0;cost=0;}
};

class dijkstra{
public:
	vector<vector<edge> > E;
	vector<int> dist;
	int start;
	dijkstra(int n): E(n),dist(n){}

	void add_edge(int x,int y,int c){
		edge e;
		e.to = y,e.cost = c;
		E[x].push_back(e);
	}

	void shortest_path(){
		priority_queue<P,vector<P>,greater<P> > que;
		dist.assign(dist.size(),INF);

		dist[start] = 0;
		que.push(P(0,start));

		while(!que.empty()){
			 P p = que.top();
			 que.pop();
			 int v = p.second;
			 if(dist[v] < p.first) continue;

			 for(int i = 0; i < E[v].size(); i++){
			 	edge e = E[v][i];
			 	if(dist[v] +  e.cost < dist[e.to]){
			 		dist[e.to] = dist[v] +  e.cost;
			 		que.push(P(dist[e.to],e.to));
			 	}
			 }
		}
	}


};

int main()
{
	int n;
	cin >> n;
	dijkstra dij(n);
	for(int i = 0; i < n; i++){
		int u,k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v,c;
			cin >> v >> c;
			dij.add_edge(u,v,c);
		}
	}

	dij.start = 0;
	dij.shortest_path();

	for(int i = 0; i < n; i++){
		cout << i << " " <<  dij.dist[i] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 999999999
using namespace std;

int G[110][110] = {};
int mini[110];
int used[110];

void dijkstra(int n)
{
    //init
    for(int i = 0;i < n;i++){
        mini[i] = INF;
        used[i] = 0;
    }
    mini[0] = 0;

    while(true)
    {
        int v = -1;
        for(int i = 0;i < n;i++){
            if(!used[i] && (v == -1 || mini[i] < mini[v])) v = i;
        }
        if(v == -1) break;
        used[v] = 1;

        for(int i = 0;i < n;i++){
            mini[i] = min(mini[i], mini[v]+G[v][i]);
        }
    }
}

int main()
{
    int n;
    int u, k, v, c;

    cin >> n;
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++) G[i][j] = INF;
    }

    for(int i = 0;i < n;i++){
        cin >> u >> k;
        for(int j = 0;j < k;j++){
            cin >> v >> c;
            G[u][v] = c; //uiとviをつなぐコストがci
        }
    }
    dijkstra(n);
    
    for(int i = 0;i < n;i++) printf("%d %d\n", i, mini[i]);
    
    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
using namespace std;

struct uft{
    vector<ll> par;
    uft(ll n) {
        par.resize(n);
        rep(i,n)par[i]=i;
    }

    ll find(ll a){
        if(par[a]==a){
            return a;
        }else {
            return find(par[a]);
        }
    }

    void unite(ll a,ll b){
        par[find(a)]=find(b);
    }

    bool same(ll a,ll b){
        return find(a) == find(b);
    }
};

struct edge{
    ll s,t,w;
};

bool sortw(edge a,edge b) {
    return a.w < b.w;
}

int main() {
    const ll inf = 1e12;
    ll n;
    cin>>n;
    vector<vector<ll>> matrix(n,vector<ll>(n));
    rep(i,n){
        rep(j,n){
            if(i==j){
                matrix[i][j]=0;
            }else{
                matrix[i][j]=inf;
            }
        }
    }
    rep(i,n) {
        ll u,k;
        cin>>u>>k;
        rep(j,k){
            ll c,w;
            cin>>c>>w;
            matrix[u][c]=w;
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(matrix[i][k]<inf && matrix[k][j]<inf && matrix[i][j]>matrix[i][k]+matrix[k][j]){
                    matrix[i][j]=matrix[i][k]+matrix[k][j];
                }
            }
        }
    }
    rep(i,n){
        cout<<i<<" "<<matrix[0][i]<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

vector<pair<int,int> > PathList[100];
int d[100];
bool complete[100];

void dijkstra(int n,vector<pair<int,int> > PathList[]){
    rep(i,n){
        d[i] = INF;
        complete[i] = false;
    }
    d[0] = 0;
    
    int count = 0;
    
    while (count != n) {
        int mind = INF;
        int mindi = 0;
        rep(i,n){
            if (!complete[i] && d[i] < mind) {
                mind = d[i];
                mindi = i;
            }
        }
        
        complete[mindi] = true;
        count++;
        
        rep(i,PathList[mindi].size()){
            if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
                d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
            }
        }
    }
}


int main(){
    int(n);
    rep(i,n){
        int(k);int(num);
        rep(j,num){
            int(s);int(t);
            PathList[i].push_back(make_pair(s,t));
        }
    }
    
    dijkstra(n,PathList);
    
    rep(i,n){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}