Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	MAX_N      = 10000
	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;
typedef long long ll;

// #define DEBUG

const int maxint = 1e9;
struct timestamp;
vector<int> shortest;
vector<vector<pair<int, int>>> connective;

void djkstra(int x)
{
    vector<int> search = {x};
    vector<int> new_search;
    shortest[x] = 0;
    int v, d;
    while (!search.empty())
    {
        for (auto itr = search.begin(); itr != search.end(); itr++)
        {
            for (auto itr2 = connective[*itr].begin(); itr2 != connective[*itr].end(); itr2++)
            {
                v = itr2->first, d = itr2->second;
                if (shortest[v] > d + shortest[*itr])
                {
                    shortest[v] = d + shortest[*itr];
                    new_search.push_back(v);
                }
            }
        }
        search.clear();
        search = new_search;
        new_search.clear();
    }
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, v, k, x, c;
    cin >> n;
    connective.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v >> k;
        shortest.push_back(maxint);
        for (int j = 0; j < k; j++)
        {
            cin >> x >> c;
            connective[i].push_back(make_pair(x, c));
        }
    }
    djkstra(0);
    for (int i = 0; i < n; i++)
    {
        cout << i << " " << shortest[i] << endl;
    }

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)
// for (int j = 0; j < m; j++)

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>

#define INF 2000000001
#define MAX 10001
#define NIL -1

using namespace std;

typedef struct {
    int toid;
    int far;
} PATH;

vector<PATH> D[MAX];
int N;
int Dist[MAX];

void dijkstra(){//0??????????????¢??????????????£?????????
    
    bool complete[MAX];
    vector<int> S;
    
    for (int i = 0; i < N; i++) {
        complete[i] = false;
        Dist[i] = INF;
    }
 
    //???????¨????
    Dist[0] = 0;
    S.push_back(0);
    int u=0,minf;
    complete[u] = true;
    
    while (1) {
        if (S.size() == N) break;
        
        //????????????
        for (int j = 0; j < D[S[u]].size(); j++) {
            if (!complete[D[S[u]][j].toid] && Dist[S[u]] + D[S[u]][j].far < Dist[D[S[u]][j].toid]) {
                Dist[D[S[u]][j].toid] = Dist[S[u]] + D[S[u]][j].far;
            }
        }
        
        
        
        u = NIL;
        minf = INF;
        
        //?¨??????´??°
        for (int i = 0; i < S.size(); i++) {
            
            for (int j = 0; j < D[S[i]].size(); j++) {
                if (Dist[D[S[i]][j].toid] < minf && !complete[D[S[i]][j].toid]) {
                    minf = Dist[D[S[i]][j].toid];
                    u = D[S[i]][j].toid;
                }
            }
            
        }
        S.push_back(u);
        complete[u] = true;
        u = S.size()-1;//????????§u????????§??¨????????????????????????
    }
}

int main(){
    cin >> N;
    for (int i = 0; i < N; i++) {
        int bb1,bb2;
        cin >> bb1 >> bb2;
        for (int j = 0; j < bb2; j++) {
            PATH bb3;
            cin >> bb3.toid >> bb3.far;
            D[i].push_back(bb3);
        }
    }
    
    dijkstra();
    
    for (int i = 0; i < N; i++) {
        printf("%d %d\n",i,Dist[i]);
    }
    
    return 0;
}