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<bits/stdc++.h>
using namespace std;
int n,G[1001][1001],dis[1001],vis[1001],inf=10e8;
void dij(int u){
	for(int i=0;i<n;i++){
	 dis[i]=G[u][i];
	}
	int k;
	vis[u]=1;dis[u]=0;
	for(int i=0;i<n-1;i++){
		int min=inf ;
		for(int j=0;j<n;j++){
			if(vis[j]==0&&dis[j]<min){
				min=dis[j];
				k=j;
			}
		}
		vis[k]=1;
		for(int j=0;j<n;j++){
			if(!vis[j]&&dis[j]>dis[k]+G[k][j])
			dis[j]=dis[k]+G[k][j];
		}
	}
}
int main(){
	scanf("%d",&n);
	int c,v1,v2,k;
	for(int i=0;i<n;i++){
		scanf("%d%d",&v1,&k);
		for(int j=0;j<k;j++){
			scanf("%d%d",&v2,&c);
			G[v1][v2]=c;
		}
	}
	
		for(int i=0;i<n;i++)
		for(int j=0;j<n;j++){
		  if(G[i][j]==0&&i!=j){
		  	G[i][j]=inf;
		  }
	}
	
	
//	for(int i=0;i<n;i++){
//		for(int j=0;j<n;j++){
//			printf("%d ",G[i][j]);
//		}printf("\n"); 
//	}
	dij(0);
	for(int i=0;i<n;i++)
	printf("%d %d\n",i,dis[i]);
}

C++: // 単一始点最短経路 ( ダイクストラ法 )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

static const int MAX = 100;
static const int INFTY = (1 <<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int Dijkstra()
{
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    for(int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    // 初期値の設定
    d[0] = 0;
    color[0] = GRAY;

    while(1)
    {
        minv = INFTY;
        // 次に移動するべき頂点
        u = -1;

        for(int i = 0; i < n; i++)
        {
            if( minv > d[i] && color[i] != BLACK )
            {
                // 未訪問の頂点の中で, 最小のコストを持つ辺を探索する
                u = i;
                minv = d[i];
            }
        }

        if( u == -1 )
        {
            // 最初全域木が完成した
            break;
        }

        color[u] = BLACK;

        for(int v = 0; v < n; v++)
        {
            if( color[v] != BLACK && M[u][v] != INFTY )
            {
                // u → v の辺の中で, 最小コストの辺のコストを記録する
                if( d[v] > d[u] + M[u][v] )
                {
                    // コストの記録
                    d[v] = d[u] + M[u][v];
                    // 頂点 v の親を記録する
                    p[v] = u;
                    // 訪問状態の記録
                    color[v] = GRAY;
                }
            }
        }
    }

    /*
    int sum = 0;

    for(int i = 0; i < n; i++)
    {
        if( p[i] != -1 )
        {
            // 最小コストの辺の和を求める
            sum += M[i][p[i]];
        }
    }
    */

    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }

    return 0;
}

int main(void)
{

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            // 配列の初期化
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;

    for(int i = 0; i < n; i++)
    {
        cin >> u >> k;

        for(int j = 0; j < k; j++)
        {
            cin >> v >> c;

            M[u][v] = c;
        }
    }

    Dijkstra();

    return 0;

}

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

constexpr int MAX = 110;
constexpr int INF = 1e9;

int N;
int G[MAX][MAX];
bool seen[MAX];
int d[MAX];

int main(){
  for( int i = 0; i < MAX; i++ ){
    for( int j = 0; j < MAX; j++ ){
      G[i][j] = INF;
    }
  }
  
  cin >> 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;
      G[u][v] = c;
    }
  }

  for( int i = 0; i < MAX; i++ ){
    d[i] = INF;
  }
  d[0] = 0;

  while( 1 ){
    int mincost = INF;
    int u;
    for( int i = 0; i < N; i++ ){
      if( d[i] < mincost && !seen[i] ){
	mincost = d[i];
	u = i;
      }
    }

    if( mincost == INF ) break;
    seen[u] = true;
    
    for( int i = 0; i < N; i++ ){
      if( G[u][i] != INF && !seen[i] ){
	if( G[u][i] + d[u] < d[i] ){
	  d[i] = G[u][i] + d[u];
	}
      }
    }
  }

  for( int i = 0; i < N; i++ ){
    cout << i << " " << d[i] << endl;
  }

}