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 <stdio.h>
#include <iostream>
#include <queue>
#include <list>
using namespace std;

#define NODE_NUM 100

class Node
{
private:
	//int next_node_list[NODE_NUM];
	list<int> next_node_list;
	//int next_node_num;
	//int next_weight_list[NODE_NUM];
	list<int> next_weight_list;
public:
	Node();
	void AddNextNode(int id, int weight);
	void SetWeight(int weight);
	void DistributeWeight();
	int id;
	int weight_from_0;
	bool check;
};

Node::Node()
{
	//next_node_num = 0;
	weight_from_0 = -1;
	check = false;
}

Node *Node_list;

priority_queue<Node, vector<Node>, greater<Node> > que;
bool operator> (const Node &n1, const Node &n2){
	return n1.weight_from_0 > n2.weight_from_0;
};

void Node::AddNextNode(int id, int weight)
{
	//next_node_list[next_node_num] = id;
	next_node_list.push_back(id);
	//next_weight_list[next_node_num] = weight;
	next_weight_list.push_back(weight);
	//next_node_num++;
}

void Node::SetWeight(int weight)
{
	if (weight_from_0 == -1 || weight < weight_from_0) {
		weight_from_0 = weight;
	}
}

void Node::DistributeWeight()
{
	check = true;
	/*for (int i = 0; i < next_node_num; i++) {
		if (Node_list[next_node_list[i]].check == false) {
			Node_list[next_node_list[i]].SetWeight(weight_from_0 + next_weight_list[i]);
			que.push(Node_list[next_node_list[i]]);
		}
	}*/
	list<int>::iterator itr2 = next_weight_list.begin();
	for(list<int>::iterator itr = next_node_list.begin(); itr != next_node_list.end(); itr++){	
		if (Node_list[*itr].check == false) {
			Node_list[*itr].SetWeight(weight_from_0 + *itr2);
			que.push(Node_list[*itr]);
		}
		itr2++;
	}
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		Node_list[i].id = i;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			Node_list[i].AddNextNode(v, c);
		}
	}

	//weight from 0 ?
	Node_list[0].check = true;
	Node_list[0].weight_from_0 = 0;
	Node_list[0].DistributeWeight();
	while (!que.empty()) {
		int id = que.top().id;
		que.pop();
		Node_list[id].DistributeWeight();
	}

	//output
	for (int i = 0; i < n; i++) {
		cout << i << " " << Node_list[i].weight_from_0 << endl;
	}
	
	return 0;
}

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;
}