Go: package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

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

// first: cost, second: key
typedef pair<int, int> vert;

static const int MAX   = 10000;
static const int INFTY = 1 << 20;
static const int WHITE = 0;
static const int BLACK = 2;

vector<vert> adjs[MAX];

void dijkstra(int n_v, int v_start) {
    priority_queue< vert, vector<vert>, greater<vert> > visitings;
    int color[MAX];
    int costs[MAX];

    for (int i = 0; i < n_v; i++) {
        costs[i] = INFTY;
        color[i] = WHITE;
    }

    costs[v_start] = 0;
    visitings.push( make_pair(0, v_start) );

    while (! visitings.empty()) {
        vert nearest = visitings.top();
        visitings.pop();

        int next_id = nearest.second;
        color[next_id] = BLACK;

        if ( costs[next_id] < nearest.first )
            continue;

        for (int i = 0; i < adjs[next_id].size(); i++) {
            int adj  = adjs[next_id][i].first;
            int cost = adjs[next_id][i].second;

            if (color[adj] == BLACK)
                continue;

            if (costs[next_id] + cost < costs[adj]) {
                costs[adj] = costs[next_id] + cost;
                visitings.push( make_pair(costs[adj], adj) );
            }
        }
    }

    for (int i = 0; i < n_v; i++) {
        cout << i << " " << costs[i] << "\n";
    }
}

int main() {
    std::ios::sync_with_stdio(false);

    int n_v;
    cin >> n_v;

    for (int i = 0; i < n_v; i++) {
        int vert_id, n_adjs;
        cin >> vert_id >> n_adjs;

        for (int j = 0; j < n_adjs; j++) {
            int adj, cost;
            cin >> adj >> cost;
            adjs[vert_id].push_back( make_pair(adj, cost) );
        }
    }

    dijkstra(n_v, 0);
}

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

#define INFTY (1 << 30)

//???????????????
enum Color {
	WHITE,
	GRAY,
	BLACK,
};


//SSSP
void Dijkstra(vector<pair<int, int>> *v_w_m, int verNum) {

	//???????¨????
	priority_queue<pair<int, int>> pQ;
	int distance[10000];
	Color color[10000];
	int parent[10000];
	for (int i = 0; i < verNum; i++) {
		color[i] = WHITE;
		distance[i] = INFTY;
		parent[i] = -1;
	}
	distance[0] = 0;
	pQ.push(make_pair(0, 0));


	//SSSP??????
	while (!pQ.empty()) {

		//??°??¬????????????????????????????°?????????????????????¶
//		int min_cost = INFTY;
		int subScript;
		pair<int, int> wei_sub_map = pQ.top();
		pQ.pop();
		subScript = wei_sub_map.second;
		//for (int i = 0; i < verNum; i++) {
		//	if (color[i] != BLACK && distance[i] < min_cost) {
		//		min_cost = distance[i];
		//		subScript = i;
		//	}
		//}

		//?????????????????????
		color[subScript] = BLACK;

		//???????????????????????°??????????????????????????????????????????
		//?????????????????¨4169407B?????¨??????0.01sec????????????
		if (distance[subScript] < wei_sub_map.first * -1)
			continue;

		//??£??\?????°??¬??????
		for (int i = 0; i < v_w_m[subScript].size(); i++) {
			int outV = v_w_m[subScript][i].first;
			if (color[outV] == BLACK) continue;
			if (distance[outV] < distance[subScript] + v_w_m[subScript][i].second) continue;

			distance[outV] = distance[subScript] + v_w_m[subScript][i].second;
			parent[outV] = subScript;
			color[outV] = GRAY;
			pQ.push(make_pair(distance[outV] * -1, outV));
		}
	}

	//??????
	int weight_sum = 0;
	for (int i = 0; i < verNum; i++) {
		cout << i << " " << (distance[i] == INFTY ? -1 : distance[i]) << endl;
	}
}


int main() {

	int verNum;
//	int verValWeight[100][100];
	vector<pair<int, int>> v_w_m[10000];
	int parent[10000];

	//???????¨????
//	v_w_m = new vector<pair<int, int>>();
	cin >> verNum;
	//for (int i = 0; i < verNum; i++)
	//	for (int j = 0; j < verNum; j++)
	//		verValWeight[i][j] = INFTY;

	//??\?????????
	for (int i = 0; i < verNum; i++) {
		int verVal, outNum;
		cin >> verVal >> outNum;
		for (int j = 0; j < outNum; j++) {
			int outVerVal, weight;
			cin >> outVerVal >> weight;
//			v_w_m[verVal].push_back(make_pair(outVerVal, weight));
			v_w_m[verVal].push_back(make_pair(outVerVal, weight));
			//			verValWeight[i][outVerVal] = weight;
		}
	}

	//SSSP
	Dijkstra(v_w_m, verNum);

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int n;
void search(vector<vector<int> > &G1, vector<vector<int> > &G2, int *d, bool *v)
{
    int mini, minv;
    while (1)
    {
        bool iscomp = true;
        minv = INFTY;
        rep(i, 0, n)
        {
            if (!v[i] && d[i] < minv)
            {
                mini = i;
                minv = d[i];
                iscomp = false;
            }
        }
        if (iscomp)
            break;
        v[mini] = true;
        rep(i, 0, G1[mini].size())
        {
            int tmp = G1[mini][i];
            if (!v[tmp])
            {
                int tmptime = minv + G2[mini][i];
                if (tmptime < d[tmp])
                    d[tmp] = tmptime;
            }
        }
    }
}
int main()
{
    cin >> n;
    vector<vector<int> > G1(n, vector<int>(0)), G2(n, vector<int>(0));
    int d[n];
    bool v[n] = {};
    rep(i, 0, n) d[i] = INFTY;
    int utmp, ktmp, vtmp, ctmp;
    rep(i, 0, n)
    {
        cin >> utmp >> ktmp;
        rep(j, 0, ktmp)
        {
            cin >> vtmp >> ctmp;
            G1[utmp].push_back(vtmp);
            G2[utmp].push_back(ctmp);
        }
    }
    d[0] = 0;
    search(G1, G2, d, v);
    rep(i, 0, n)
    {
        printf("%d %d\n", i, d[i]);
    }
}