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 <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
#define INF 0x3f3f3f3f

int N;
vector <pii> G[101];
int mcos[101];

void dijkstra(int s)
{
   priority_queue < pii, vector<pii>, greater<pii> > pq;
   pq.push( mkp(0, s) );
   memset( mcos, INF, sizeof(mcos) );
   mcos[s] = 0;
   while( !pq.empty() ){
      const pii tmp = pq.top(); pq.pop();
      if( mcos[tmp.se] < tmp.fi )continue;
      for( const auto& v : G[tmp.se] ){
         const int nc = v.fi + tmp.fi;
         if( chmin( mcos[v.se], nc )) pq.push( mkp(nc, v.se) );
      }
   }
}

signed main()
{
   FAST();
   cin >> N;

   rep(i, N){
      int u, k, to, c;
      cin >> u >> k;
      while(k--){
         cin >> to >> c;
         G[i].pb( mkp(c,to) );
      }
   }
   dijkstra(0);
   rep(i, N) cout << i << ' ' << mcos[i] << '\n';
}

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

#include<queue>

using namespace std;

static const int MAX_N = 100;
static const int INFTY = (1 <<21);

static const int NO = 0;
static const int YES = 1;

// グラフ情報を保持する配列
int ary_graph[MAX_N + 1][MAX_N + 1];
// 辺の関係を保持する配列
vector<int> v_connection[MAX_N];
// スタートからの距離を保持する配列
int ary_distance[MAX_N + 1];
// 各頂点の状態を保持する配列 ( 確定 or 未確定 )
int ary_vertex[MAX_N];

void Dijkstra_Method(int start_v, int all_v);

int main(void)
{

    int n, u, k, v, c;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        ary_vertex[i] = NO;

        // 全頂点のスタートからの距離を無限大とする
        ary_distance[i] = INFTY;

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

    cin >> n;

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

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

            // 隣接行列の設定
            ary_graph[u][v] = c;
            // 辺の関係の保存
            v_connection[u].push_back(v);
        }
    }

    Dijkstra_Method(0, n);

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ary_distance[i] << endl;;
    }

    return 0;
}

// ダイクストラ法を実施する関数
// start_v : スタートする頂点のNo.
// all_v   : 全頂点の数
void Dijkstra_Method(int start_v, int all_v)
{
    int vertex_num = 0;
    int ele, confirm_v, tmp_distance;
    int min_distance, min_v;

    // スタート地点の距離はゼロとする
    ary_distance[start_v] = 0;
    // 確定した頂点を設定
    confirm_v = start_v;
    ary_vertex[confirm_v] = YES;

    // 全頂点のスタートからの距離が確定するまで, ループを継続する
    while( vertex_num != all_v )
    {

        min_v = INFTY;
        min_distance = INFTY;

        // 確定した頂点から, [直接つながっている] かつ [未確定]の頂点の距離を計算する
        for(int i = 0; i < v_connection[confirm_v].size(); i++)
        {
            // 辺のつながっている頂点No.
            ele = v_connection[confirm_v][i];

            // confirm_v の頂点を経由した場合の距離 ( 経由する頂点までの距離 + 辺の重み )
            tmp_distance = ary_distance[confirm_v] + ary_graph[confirm_v][ele];

            if( ary_vertex[ele] == NO )
            {
                // 未確定の頂点について検討する

                if( tmp_distance < ary_distance[ele] )
                {
                    // 最小値で距離情報を更新する
                    ary_distance[ele] = tmp_distance;
                }

                if( min_distance > tmp_distance )
                {
                    // confirm_v の頂点から, 最小距離の頂点を探す
                    min_distance = tmp_distance;
                    min_v = ele;
                }
            }
        }

        // 次に進むべき頂点の確定
        if( min_v != INFTY )
        {
            confirm_v = min_v;
            ary_vertex[confirm_v] = YES;
        }

        vertex_num++;

    }

    return;
}