Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strings"
	"strconv"
)
var MAX = 1000000
type Vertex struct{
	Value int
	Routes map[int]int
	Done bool
}
func NewVertex(value int) *Vertex{
	routes := make(map[int]int)
	// for i, _ := range routes {
	// 	routes[i] = MAX
	// }
	return &Vertex{ value, routes, false }
}

func (v *Vertex) SetRoute(key, weight int) {
	v.Routes[key] = weight
}

type Path struct {
	Key int
	Weight int
}

var count = 0
func ShortestRoutes(list []*Vertex) []int {
	// create result table
	result  := make([]int, len(list))
	// fmt.Println(result)
	for i, _ := range result {
		result[i] = MAX
	}

	queue := make([]Path, 0)
	queue = append(queue, Path{0, 0})
	result[0] = 0

	for len(queue) != 0 {
		count++
		path := queue[0]
		queue = queue[1:]
		for key, weight := range list[path.Key].Routes {
			// fmt.Println(list[path.Key].Routes)
			// set to result
			// fmt.Printf("Path(%d, %d) ? result[%d] => %d, wieght: %d\n", path.Key, path.Weight, key, result[key], weight)
			if path.Weight + weight < result[key] {
				result[key] = path.Weight + weight 
				queue = append(queue, Path{key, result[key]})
			// } else if !list[key].Done {
			// 	queue = append(queue, Path{key, result[key]})
			}
		}
		list[path.Key].Done = true
	}
	return result
}
func main() {
	var n int
	fmt.Scanf("%d", &n)
	list := make([]*Vertex, n)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scanner.Scan()
		elements := strings.Split(scanner.Text(), " ")
		value, _ := strconv.Atoi(elements[0])
		list[i] = NewVertex(value)
		for j := 2; j < len(elements); j += 2 {
			key, _    := strconv.Atoi(elements[j])
			weight, _ := strconv.Atoi(elements[j + 1])
			list[i].SetRoute(key, weight)
		}
	}

	result := ShortestRoutes(list)
	for i := 0; i < len(result); i++ {
		fmt.Printf("%d %d\n", i, result[i]);
	}
	// fmt.Printf("count: %d\n", count)
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

vector<pair<int, int> > adj[10000];
int cost[10000];
int done[10000];

void dijkstra()
{
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;
	pair<int, int> next;	/* first: cost, second: index */
	int index;

	cost[0] = 0;
	PQ.push(make_pair(0, 0));

	while (!PQ.empty()) {
		next = PQ.top();
		PQ.pop();

		index = next.second;

		if (done[index] == 1) continue;
		done[index] = 1;

		rep(i, adj[index].size()) {
			if ((done[adj[index][i].second] == 0)
				&& (cost[adj[index][i].second] > cost[index] + adj[index][i].first)) {
				cost[adj[index][i].second] = cost[index] + adj[index][i].first;
				PQ.push(make_pair(cost[adj[index][i].second], adj[index][i].second));
			}
		}
	}
}

int main()
{
	int n, u, k, v, c;


	cin >> n;
	rep(i, n) {
		cost[i] = 1000000001;
		done[i] = 0;
		cin >> u >> k;
		rep(j, k) {
			cin >> v >> c;
			adj[u].push_back(make_pair(c, v));
		}
	}

	dijkstra();

	rep(i, n) {
		cout << i << ' ' << cost[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
static const int MAXN=10000;
int vis[MAXN+10],d[MAXN+10];
int n;
vector<pair<int,int> >adj[MAXN];
void dijkstra()
{
    priority_queue<pair<int,int> > PQ;
    memset(d,0x3f,sizeof(d));
    memset(vis,0,sizeof(vis));
    d[0]=0;
    PQ.push(make_pair(0,0));
    vis[0]=1;
    while(!PQ.empty())
    {
        pair<int,int> f=PQ.top();
        PQ.pop();
        int u=f.second;
        vis[u]=2;
        if(d[u]<f.first*(-1))
            continue;
        for(int j=0;j<adj[u].size();j++)
        {
            int v=adj[u][j].first;
            if(vis[v]==2)
                continue;
            if(d[v]>d[u]+adj[u][j].second)
            {
                d[v]=d[u]+adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                vis[v]=1;
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<i<<" "<<(d[i]==INF?-1:d[i])<<endl;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),cout.tie(0);
    int u,k,v,c;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v>>c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
int i, j, k;

static const int MAX = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

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

void dijkstra() {
	int d[MAX], p[MAX], color[MAX];
	priority_queue<pair<int, int>> PQ;
	rep(i, n) {
		color[i] = White;
		d[i] = INF;
	}
	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = Gray;
	while (!PQ.empty()) {
		pair<int, int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		color[u] = Black;
		if (d[u] < f.first * (-1)) continue;
		rep(j, adj[u].size()) {
			int v = adj[u][j].first;
			if (color[v] == Black) continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * -1, v));
				color[v] = Gray;
			}
		}
	}
	rep(i, n) {
		cout << i << ' ' << (d[i] == INF ? -1 : d[i]) << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, n) {
		int u,k;
		cin >> u >> k;
		rep(j, k) {
			int v, c;
			cin >> v >> c;
			adj[u].pb(make_pair(v, c));
		}
	}
	dijkstra();
	return 0;
}