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

C++: #include <cstdio>
#include <queue>
#include <vector>
using namespace std;
#define INF 1 << 30
typedef pair<int, int> P;

int n, M[100][100], d[100];

void dijkstra(void) {
    int i, u, v;
    P t;
    priority_queue<P, vector<P>, greater<P> > pq;

    pq.push(make_pair(0, 0));
    while (!pq.empty()) {
        t = pq.top(); pq.pop();
        v = t.first;
        u = t.second;

        if (d[u] != INF) continue;
        d[u] = v;

        for (i = 0; i < n; i++) {
            if (d[i] != INF || M[u][i] == INF) continue;
            pq.push(make_pair(v + M[u][i], i));
        }
    }
}

int main(void) {
    int i, j, u, k, v, c;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        d[i] = INF;
        for (j = 0; j < n; j++) M[i][j] = INF;
    }

    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        for (j = 0; j < k; j++) {
            scanf("%d %d", &v, &c);
            M[u][v] = c;
        }
    }

    dijkstra();

    for (i = 0; i < n; i++) printf("%d %d\n", i, d[i]);

    return 0;
}

C++: #include <iostream>
using namespace std;
int n,m[100][100],d[100];
void mins(){
    int u,min,color[100];
    for(int i=0;i<n;i++){
        d[i]=1000000000;
        color[i]=1;
    }
    d[0]=0;
    while(1){
        min=1000000000;
        u=-1;
        for(int i=0;i<n;i++){
            if(color[i]!=3&&d[i]<min){
                u=i;
                min=d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u]=3;
        for(int i=0;i<n;i++){
            if(m[u][i]!=-1){
                if(d[i]>min+m[u][i]){
                    d[i]=min+m[u][i];
                }
            }
        }
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=-1;
        }
    }
    int a,k,c,v;
    for(int i=0;i<n;i++){
        cin>>a>>k;
        for(int j=0;j<k;j++){
            cin>>c>>v;
            m[a][c]=v;
        }
    }
    mins();
    for(int i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int x[1000][1000];
int y[1000];

int main() {
	memset(x, 127, sizeof(x));
	memset(y, 127, sizeof(y));
	int n, a, b, c, d;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		for (int i = 0; i < b; i++) {
			cin >> c >> d;
			x[a][c] = d;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				y[k] = min(y[k], y[j] + x[j][k]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << y[i] << endl;
	}
	return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000010

int n;
int M[100][100];
int color[100],d[100],p[100];

void dik(int s){
  
  rep(i,n){
    color[i]=WHITE;
    d[i]=INF;
    p[i]=-1;
  }
  d[s]=0;
  
  int minc,u;
  while(1){
    minc=INF; 
    rep(i,n){
      if(color[i] != BLACK && d[i]<minc){
        minc=d[i];
        u=i;
      }
    }
    
    if(minc==INF) break;
    color[u]=BLACK;
    
    rep(v,n){
      if(color[v] != BLACK && M[u][v] != -1){
        if(d[u]+M[u][v]<d[v]){
          d[v]=d[u]+M[u][v];
          p[v]=u;
          color[v]=GRAY;
        }
      }
    }    
  }
  
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) M[i][j]=INF;
  }
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    rep(j,y){
      cin>>z;
      cin>>M[x][z];
    }
  }
  
  dik(0);
  rep(i,n) cout<<i<<" "<<d[i]<<endl;
  
  return 0;
}