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<cstdlib>
// 0origin
// referred to http://www.deqnotes.net/acmicpc/dijkstra/
// 単純な方法の方

#define MAX_DATA 100
#define INF 1000001
#define NIL -2

int n;
typedef struct {
    int num;
    // ここから伸びるエッジの情報
    int edges_to[MAX_DATA]; // 各接続先の番号
    int edges_cost[MAX_DATA]; // 各エッジのコスト
    int edges_size; // エッジの本数
    
    // ダイクストラ法のためのデータ
    bool done; // 確定ノードか否か
    int cost; // このノードへの現時点で判明しているコスト
}Node;

Node node[MAX_DATA];

int min(int x, int y){
    return x < y ? x : y;
}

void Init(){
    for (int i = 0; i < n; i++) {
        node[i].done = false;
        node[i].cost = INF;
    }
}

void Dijkstra(){
    Init();
    node[0].cost = 0;
    /*
    while (1) {
        Node doneNode;
        doneNode.cost = NIL;
        for (int i = 0; i < n; i++) {
            printf("node[%d].done:%s cost:%d doneNode.cost:%d\n", i, node[i].done == true ? "true" : "false", node[i].cost, doneNode.cost);
            if (node[i].done == true || node[i].cost == INF) {
                continue;
            }
            if (doneNode.cost == NIL || node[i].cost < doneNode.cost) {
                doneNode = node[i];
            }
        }
        if(doneNode.cost == NIL){
            break;
        }
        
        .done = true;
        
        for (int i = 0; i < doneNode.edges_size; i++) {
            int to = doneNode.edges_to[i];
            int cost = doneNode.cost + doneNode.edges_cost[i];
            if (node[to].cost < 0 || cost < node[to].cost) {
                node[to].cost = cost;
            }
        }
    }*/
    
    Node doneNode[MAX_DATA];
    node[0].done = true;
    doneNode[0] = node[0];
    int NOFdoneNode = 1;
    while (NOFdoneNode < n) {
        int mincost = INF;
        for(int i = 0; i < NOFdoneNode; i++){ // doneNodeを動かす
            for(int j = 0; j < doneNode[i].edges_size; j++){ // doneNodeから伸びているnodeをうごかす
                //printf("%d to %d\n", doneNode[i].num, doneNode[i].edges_to[j]);
                if (node[doneNode[i].edges_to[j]].done) { // 確定ノードと確定ノードがつながっていたらスルー
                    //printf(" through\n");
                    continue;
                }
                //printf(" %d >?< %d\n", node[doneNode[i].edges_to[j]].cost, doneNode[i].cost + doneNode[i].edges_cost[j]);
                if(node[doneNode[i].edges_to[j]].cost >= doneNode[i].cost + doneNode[i].edges_cost[j]){ // 確定nodeたちからの最短距離を記録
                    node[doneNode[i].edges_to[j]].cost = doneNode[i].cost + doneNode[i].edges_cost[j];
                    if(mincost > node[doneNode[i].edges_to[j]].cost){ // mincostが更新されたらdoneNodeの最後尾を更新
                        mincost = node[doneNode[i].edges_to[j]].cost;
                        doneNode[NOFdoneNode] = node[doneNode[i].edges_to[j]];
                    }
                }
            }
        }
        node[doneNode[NOFdoneNode].num].done = true;
        //printf("%d is done\n", doneNode[NOFdoneNode].num);
        
        /*for(int i = 0; i < NOFdoneNode+1; i++){
            printf("%d,", doneNode[i].num);
        }
        printf("\n\n");*/
        NOFdoneNode++;
    }
}

int main(){
    int m;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++){
        scanf("%d%d", &m ,&m);
        node[i].edges_size = m;
        node[i].num = i;
        for (int j = 0; j < m; j++) {
            scanf("%d %d", &node[i].edges_to[j], &node[i].edges_cost[j]);
        }
        node[i].edges_to[m] = NIL;
        node[i].edges_cost[m] = NIL;
    }
    
#ifdef D
    for (int i = 0; i < n; i++) {
        printf("%d:", i);
        for (int j = 0; ; j++) {
            if(node[i].edges_to[j] == NIL){
                break;
            }
            printf("%d(%d) ", node[i].edges_to[j], node[i].edges_cost[j]);
        }
        printf("\n");
    }
#endif
    
    Dijkstra();
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, node[i].cost);
    }
    
    return 0;
}