Go: package main

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

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: #include<iostream>
#include<queue>
#include<algorithm>
#include<functional>
#define MAX 10000
#define INFTY (1<<20)
#define MPII(a,b) make_pair((a),(b))
#define PII pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

class Node
{
public:
	Node() {};
	int d;
	bool done;
	priority_queue<PII, vector<PII>, greater<PII>> E;
};

int main()
{
	queue<int> order;
	Node nodes[MAX];
	REP(i, MAX)
	{
		nodes[i].done = false;
		nodes[i].d = INFTY;
	}
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		int ID, m;
		cin >> ID >> m;
		REP(l, m)
		{
			int v, w;
			cin >> v >> w;
			PII p = MPII(w, v);
			nodes[ID].E.push(p);
		}
	}
	int now = 0;
	order.push(now);
	nodes[now].d = 0;
	while (1)
	{
		if (nodes[now].done == false)
		{
			while (!nodes[now].E.empty())
			{
				PII temp = nodes[now].E.top();
				nodes[now].E.pop();
				int nextv = temp.second;
				order.push(nextv);
				int w = temp.first;
				if (nodes[nextv].d > nodes[now].d + w)
				{
					nodes[nextv].d = nodes[now].d + w;
				}
			}
			nodes[now].done = true;
		}
		order.pop();
		if (order.empty())break;
		now = order.front();
	}
	REP(i, n)
	{
		cout << i << " " << nodes[i].d << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <climits>
#include <vector>
using namespace std;
typedef unsigned short ushort;

class blanch{
	public:
		bool visited;
		int distance;
		ushort from;
		ushort to;
};
typedef vector <blanch> vb;
typedef vector <vb> vvb;

int make_graph(vvb &graph, vb &nodes){

	int n=nodes.size();
	for (ushort i=0; i<n; i++){
		nodes[i].visited = false;
		nodes[i].distance = INT_MAX;
	}

	for (ushort i=0; i<n; i++){
		int i2, n2;
		cin>>i2;
		cin>>n2;

		blanch bl0;
		bl0.visited = false;
		bl0.from = i2;

		for (ushort j=0; j<n2; j++){
			ushort j2;
			cin>>bl0.to;
			cin>>bl0.distance;

			graph[i2].push_back(bl0);
		}
	}
	return 0;
}

int Shortest_Path(vvb &graph, vb &nodes){

	int n = graph.size(), p1=0;
	nodes[p1].distance = 0;
	int p2;
	while (p1 != -1){
		nodes[p1].visited=true;
		for (int i = 0; i < (int)graph[p1].size(); i++){
			blanch tmp = graph[p1][i];
			p2=tmp.to;
			if (nodes[p2].visited==false){
				int tmp2 = tmp.distance + nodes[p1].distance;
				if (tmp2 < nodes[p2].distance){
					tmp.distance = tmp2;
					nodes[p2] = tmp;
				}
			}
		}
		p1 = -1;
		int tmp;
		tmp = INT_MAX;
		for (int i=0; i<n; i++){
			if (nodes[i].visited==false && nodes[i].distance<tmp){
				p1 = i;
				tmp = nodes[i].distance;
			}
		}
	}
	return 0;
}

int resultout(vb &nodes){
	int n = nodes.size();
	for (int i=0; i<n; i++){
		cout<<i<<" "<<nodes[i].distance<<endl;
	}
	return 0;
}

int main(void){

	int n;
	cin>>n;
	vvb G(n, vb());
	vb nodes(n);

	make_graph(G, nodes);

	Shortest_Path(G, nodes);

	resultout(nodes);
	G.clear();
	nodes.clear();

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<utility>
#include<limits>
using namespace std;
typedef pair<int, int> Edge;
int main()
{
	int n; cin >> n;
	vector< vector< Edge > > lists;

	for (int i = 0; i < n; i++)
	{
		vector<Edge> list;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			Edge edge;
			cin >> edge.second >> edge.first;
			list.push_back(edge);
		}
		lists.push_back(list);
	}

	vector<int> costs(n, INT32_MAX);
	costs[0] = 0;
	priority_queue<Edge> queue;
	for (Edge edge : lists[0])
		queue.push(edge);

	while (!queue.empty())
	{
		Edge edge = queue.top(); queue.pop();
		int dest = edge.second;
		int cost = edge.first;
		if (costs[dest] < cost)continue;
		int new_cost = costs[edge.second] = edge.first;

		for (Edge next : lists[dest])
		{
			next.first += new_cost;
			if(costs[next.second]==INT_MAX)
				queue.push(next);
		}
	}
	for (int i = 0; i < n; i++)
		cout << i << " " << costs[i] << endl;

	char c;
	cin >> c;

	return 0;
}