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{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} 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]
}

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] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for i, v := range adjacents {
		if v >= 0 {
			edges = append(edges, Edge{start: currentNode, end: i, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

vector<pair<int,int> > PathList[10000];
int d[10000];
bool complete[10000];

void dijkstra(int n,vector<pair<int,int> > PathList[]){
    priority_queue<pair<int,int> > PQ;
    
    rep(i,n){
        d[i] = INF;
        complete[i] = false;
    }
    d[0] = 0;
    PQ.push(make_pair(-d[0],0));
    int count = 0;
    
    while (count != n) {
        //select
        int mindi;
        while (1) {
            if (!complete[PQ.top().second]) {
                mindi = PQ.top().second;
                PQ.pop();
                break;
            }
            PQ.pop();
        }
        
        complete[mindi] = true;
        count++;
        
        //update
        rep(i,PathList[mindi].size()){
            if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
                d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
                PQ.push(make_pair(-PathList[mindi][i].second + d[mindi],PathList[mindi][i].first));
            }
        }
    }
}


int main(){
    int(n);
    rep(i,n){
        int(k);int(num);
        rep(j,num){
            int(s);int(t);
            PathList[i].push_back(make_pair(s,t));
        }
    }
    
    dijkstra(n,PathList);
    
    rep(i,n){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <limits>
using namespace std;

struct vec {
    int t, c;
    vec(int to, int cost):t(to),c(cost){}
    bool operator>(const vec &r)const{return t>r.t;}
};
vector<vec> adj[10000];
int d[10000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) d[i]=numeric_limits<int>::max();
    for(int i=0; i<n; i++) {
        int u,k;
        cin>>u>>k;
        adj[u].reserve(k);
        for(int j=0; j<k; j++) {
            int v,c;
            cin>>v>>c;
            adj[u].push_back(vec(v,c));
        }
    }
    priority_queue<vec, vector<vec>, greater<vec> >q;
    q.push(vec(0,0));
    while(!q.empty()) {
        vec e=q.top();
        q.pop();
        if(d[e.t]<=e.c) continue;
        d[e.t]=e.c;
        for(vector<vec>::iterator it=adj[e.t].begin(); it!=adj[e.t].end(); ++it) q.push(vec(it->t, e.c+it->c));
    }
    for(int i=0; i<n; i++) cout<<i<<' '<<d[i]<<'\n';
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <utility>
using namespace std;

const int MAX = 10000;
const int INF = 1 << 29;

int n;
vector<pair<int, int>> cost[MAX];

void solve()
{
	int ans[MAX];
	bool visited[MAX];
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> PQ;

	for (int i = 0; i < n; i++) {
		ans[i] = INF;
		visited[i] = false;
	}

	ans[0] = 0;

	PQ.push(make_pair(0, 0));

	while (PQ.empty() == false) {
		pair<int, int> p = PQ.top();
		PQ.pop();

		visited[p.second] = true;

		if (ans[p.second] < p.first) {
			continue;
		}

		for (unsigned int i = 0; i < cost[p.second].size(); i++) {
			int v = cost[p.second][i].second;

			if (visited[v] == true) {
				continue;
			}

			if (ans[v] > ans[p.second] + cost[p.second][i].first) {
				ans[v] = ans[p.second] + cost[p.second][i].first;
				PQ.push(make_pair(ans[v], v));
			}
		}
	}


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

int main()
{
	cin >> n;

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

		for (int j = 0; j < num; j++) {
			int v, c;
			cin >> v >> c;
			cost[i].push_back(make_pair(c, v));//(?????¢,?????????
		}
	}


	solve();

	return 0;
}