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 <stdio.h>
#include <iostream>
#include <queue>
#include <list>
using namespace std;

class Node
{
private:
	list<int> next_node_list;
	list<unsigned int> next_weight_list;
public:
	Node();
	void AddNextNode(int id, unsigned int weight);
	void SetWeight(unsigned int weight);
	void DistributeWeight();
	unsigned int weight_from_0;
	bool check;
};

Node::Node()
{
	weight_from_0 = -1;
	check = false;
}

Node *Node_list;

struct GreatNode
{
	bool operator()(const Node *n1, const Node *n2) const;
};
bool GreatNode::operator()(const Node *n1, const Node *n2) const
{
	return n1->weight_from_0 > n2->weight_from_0;
}
priority_queue<Node*, vector<Node*>, GreatNode > que;

void Node::AddNextNode(int id, unsigned int weight)
{
	next_node_list.push_back(id);
	next_weight_list.push_back(weight);
}

void Node::SetWeight(unsigned int weight)
{
	if (weight_from_0 == -1 || weight < weight_from_0) {
		weight_from_0 = weight;
	}
}

void Node::DistributeWeight()
{
	check = true;
	list<unsigned int>::iterator itr2 = next_weight_list.begin();
	for(list<int>::iterator itr = next_node_list.begin(); itr != next_node_list.end(); itr++){	
		if (Node_list[*itr].check == false) {
			Node_list[*itr].SetWeight(weight_from_0 + *itr2);
			que.push(&Node_list[*itr]);
		}
		itr2++;
	}
	next_node_list.clear();
	next_weight_list.clear();
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			Node_list[i].AddNextNode(v, c);
		}
	}

	//weight from 0 ?
	Node_list[0].check = true;
	Node_list[0].weight_from_0 = 0;
	Node_list[0].DistributeWeight();
	while (!que.empty()) {
		Node *node = que.top();
		que.pop();
		node->DistributeWeight();
	}

	//output
	for (int i = 0; i < n; i++) {
		cout << i << " " << Node_list[i].weight_from_0 << endl;
	}
	
	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;
			queue.push(next);
		}
	}
	for (int i = 0; i < n; i++)
		cout << i << " " << costs[i] << endl;

	char c;
	cin >> c;

	return 0;
}

C++: #include <iostream> 
#include <queue>
#include <algorithm>
#define MAX 100
#define INF (1<<21)
#define WHITE 0
#define GRAY  1
#define BLACK 2
using namespace std;

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

void Dijkstra() 
{
    priority_queue<pair<int,int>> PQ;
    int next, min_cost;
    int color[n], dist[n];

    for (int i = 0; i < n; ++i) 
    {
        color[i] = WHITE;
        dist[i] = INF;
    }

    dist[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;

    while(! PQ.empty())
    {
        pair<int, int> next = PQ.top(); PQ.pop();
        int u = next.second;

        color[u] = BLACK;

        if (dist[u] < next.first * (-1)) continue;

        for (int i = 0; i < adj_list[u].size(); ++i) 
        {
            int v = adj_list[u][i].first;
            if (color[v] == BLACK) continue;
            if (dist[v] > dist[u] + adj_list[u][i].second)
            {
                color[v] = GRAY;
                dist[v] = dist[u] + adj_list[u][i].second;
                PQ.push(make_pair(dist[v]*(-1), v));
            }
        }
    }
    
    int sum = 0;
    for (int i = 0; i < n; ++i) 
    {
        cout << i << ' ' << (dist[i] != INF ? dist[i] : -1) << endl; 
    }
}

int main() 
{
    int id, deg, v, w;

    cin >> n;
    for (int i = 0; i < n; ++i) 
    {
        cin >> id >> deg;
        for (int j = 0; j < deg; ++j) 
        {
            cin >> v >> w;
            adj_list[id].push_back(make_pair(v, w));
        }
    }

    Dijkstra();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

enum state { New, Working, Done };

int main()
{
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> al(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			al[u].push_back(make_pair(v, c));
		}
		sort(al[i].begin(), al[u].end());
	}

	vector<int> d(n, INT_MAX);
	vector<state> status(n);
	d[0] = 0;
	status[0] = Working;
	priority_queue<pair<int, int>> pq;  // pq.first: value, pq.second: node
	pq.push(make_pair(0, 0));
	while (!pq.empty()) {
		int node = pq.top().second;
		int value = pq.top().first;
		pq.pop();
		status[node] = Done;

		if (d[node] < value*(-1)) continue;

		for (int i = 0; i < al[node].size(); i++) {
			int nextNode = al[node][i].first;
			int nextValue = al[node][i].second;
			if (status[nextNode] == Done) continue;
			if (d[node] + nextValue < d[nextNode]) {
				d[nextNode] = d[node] + nextValue;
				pq.push(make_pair(d[nextNode] * (-1), nextNode));
				status[nextNode] = Working;
			}
		}
	}

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