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 <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


template <typename T> class Dijkstra{
    vector<pair < T, int >>* edges;
    int* par;
    T* Distance;
    int size;

public:
    Dijkstra(int n){
        size = n;
        edges = new vector<pair<T , int> >[n];
        Distance = new T[n];
        par = new int[n];
    };

    T Get_Distance(int x){
        if(x < 0 or x>= size) return T(-1);
        else return Distance[x];
    };

    void add_edge(T dist, int s,int t);

    void Disp_Graph();

    void Get_Shortest(int s);



};


template<typename T> void Dijkstra<T>::add_edge(T dist, int s,int t){
    edges[s].push_back( mp(dist, t));
}

template<typename T> void Dijkstra<T>::Disp_Graph(){
    REP(i,size){
        REP(j,edges[i].size()){
            cout << edges[i][j].se << " " << edges[i][j].fi <<endl;
        }
        cout << endl;
    }
}


template<typename T> void Dijkstra<T>::Get_Shortest(int s){
    REP(i,size) Distance[i] = T(INF);
    reversed_priority_queue< pair<T, int > > Q;
    bool used[size];
    REP(i,size) used[i] = false;
    REP(i,size) par[i] = -1;
    int Q_size = 1;
    Distance[s] = 0;
    Q.push( mp(T(0),s ) );
    while(Q_size){
        pair < T, int > x = Q.top();
        Q.pop();
        Q_size --;
        if( used[x.se]) continue;
        used[x.se] = true;
        REP(i,edges[x.se].size()){
            pair < T, int > y = edges[x.se][i];
            if(  Distance[y.se] > Distance[x.se] + y.fi){
                Distance[y.se] = Distance[x.se] + y.fi;
                Q.push( mp ( Distance[y.se],y.se) );
                Q_size ++;
                par[y.se] = x.se;
            }
        }

    }

}











signed main(){
    int n,m,s;
    cin >> n;
    Dijkstra<int> D(n);
    int t1,d1;
    REP(i,n){
        int u,k;
        scanf("%lld%lld",&u,&k);
        REP(j,k){
            scanf("%lld%lld",&t1,&d1);
            D.add_edge(d1,u,t1);
        
        }
    }


    D.Get_Shortest(0);
    int tmp = 0;
    REP(i,n){
        printf("%lld %lld\n",i,D.Get_Distance(i));
    }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

static const int N = 10000;
static const int INF = 1000000;

struct Vertex {
    int id;
    bool in_S;
    int min_cost;
};

bool operator>(const Vertex &vertex1, const Vertex &vertex2)
{
    return vertex1.min_cost > vertex2.min_cost;
}


class SSSP {
private:
    vector<pair<int, int> > adj[N];
    Vertex vertex[N];
    int n;

public:
    SSSP()
    {
        cin >> n;
        int id;
        int degree;
        int v;
        int c;
        for (int i = 0; i < n; i++)
        {
            cin >> id;
            vertex[id].id = id;
            cin >> degree;
            for (int j = 0; j < degree; j++)
            {
                cin >> v >> c;
                adj[id].push_back(make_pair(v, c));
            }
        }
    }

    void dijkstra(int start)
    {
        priority_queue<Vertex, vector<Vertex>, greater<Vertex> > PQ;
        for (int i = 0; i < n; i++)
        {
            vertex[i].in_S = false;
            vertex[i].min_cost = INF;
        }
        vertex[start].min_cost = 0;

        PQ.push(vertex[start]);

        while (!PQ.empty())
        {
            int u = PQ.top().id;
            int cost = PQ.top().min_cost;
            PQ.pop();

            vertex[u].in_S = true;

            if (vertex[u].min_cost < cost)
                continue;

            for (int j = 0; j < adj[u].size(); j++)
            {
                int v = adj[u][j].first;
                if (!vertex[v].in_S)
                {
                    if (vertex[u].min_cost + adj[u][j].second < vertex[v].min_cost)
                    {
                        vertex[v].min_cost = vertex[u].min_cost + adj[u][j].second;
                        PQ.push(vertex[v]);
                    }
                }
            }
        }
    }

    void print()
    {
        for (int i = 0; i < n; i++)
            cout << i << " " << (vertex[i].min_cost == INF ? -1 : vertex[i].min_cost) << endl;
    }
};

int main()
{
    SSSP mst;
    mst.dijkstra(0);
    mst.print();
}

C++: #include <iostream>
#include <queue>
#include <vector>
#define INF 1<<30
#define WHITE 0
#define BLACK 1
using namespace std;

int main(int argc, char* argv[]) {
    int n, u, k, v, c;
    cin >> n;

    int color[n];
    int d[n];
    vector <pair<int, int>> Adj[n];
    priority_queue <pair<int, int>> que;
    pair<int, int> top;

    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));
        }
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    que.push(make_pair(0, 0));

    while (!que.empty()){
        top = que.top();
        que.pop();
        c = (-1)*top.first;
        u = top.second;

        color[u] = BLACK;
        for (int j = 0; j < Adj[u].size(); j++){
            int v = Adj[u][j].first;
            int w = Adj[u][j].second;

            if (color[v]) continue;
            if (d[u] + w < d[v]){
                d[v] = d[u] + w;
                que.push(make_pair((-1)*d[v], v));
            }
        }
    }
    for (int i = 0; i < n; i++)
        cout << i << " " << (d[i] == INF? -1: d[i]) << endl;

    return 0;
}