Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

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

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct node {
        int id;
        int weight;
        struct node *next;
};
struct node **list;
int *dist, *prev, *heap, *heap_index, heapsize;
void Insert(int, int, int);
void downheap(int);
void upheap(int);
void PQ_Init(int);
void DijkstraPQ(int, int);
main()
{
        int i, j, n, u, k, v, c;
        scanf("%d", &n);
        list = (struct node**)malloc(sizeof(struct node*) * n);
        for (i = 0; i < n; i++) {
                dist = (int*)malloc(sizeof(int) * n);
                prev = (int*)malloc(sizeof(int) * n);
                list[i] = NULL;
        }
        for (i = 0; i < n; i++) {
                scanf("%d%d", &u, &k);
                for (j = 0; j < k; j++) {
                        scanf("%d%d", &v, &c);
                        Insert(u, v, c);
                }
        }
        DijkstraPQ(0, n);
        for (i = 0; i < n; i++) {
                struct node *p, *q;
                printf("%d %d\n", i, dist[i]);
                for (q = list[i], p = q->next; p != NULL; q = p, p = p->next) {
                        q->next = p->next;
                        free(p);
                }
                if (list[i] != NULL) {
                        free(list[i]);
                }
        }
        free(list);
        free(dist);
        free(prev);
        free(heap);
        free(heap_index);
}
void Insert(int a, int b, int weight)
{
        struct node *p = (struct node*)malloc(sizeof(struct node));
        p->id = b;
        p->weight = weight;
        p->next = list[a];
        list[a] = p;
        p = (struct node*)malloc(sizeof(struct node));
    p->id = a;
    p->weight = weight;
        p->next = list[b];
    list[b] = p;
}
void downheap(int k)
{
        int j, v = heap[k];
        while (k < heapsize / 2) {
                j = 2 * k + 1;
                if (j < heapsize - 1 && dist[heap[j]] > dist[heap[j + 1]]) j++;
                if (dist[v] <= dist[heap[j]]) break;
                heap[k] = heap[j];
                heap_index[heap[j]] = k;
                k = j;
        }
        heap[k] = v;
        heap_index[v] = k;
}
void upheap(int j)
{
        int k, v = heap[j];
        while (j > 0) {
                k = (j + 1) / 2 - 1;
                if (dist[v] >= dist[heap[k]]) break;
                heap[j] = heap[k];
                heap_index[heap[k]] = j;
                j = k;
        }
        heap[j] = v;
        heap_index[v] = j;
}
void PQ_Init(int size)
{
        int i;
        heapsize = size;
        heap = (int*)malloc(sizeof(int) * size);
        heap_index = (int*)malloc(sizeof(int) * size);
        for (i = 0; i < size; i++) {
                heap[i] = i;
                heap_index[i] = i;
        }
        for (i = size / 2 - 1; i >= 0; i--) {
                downheap(i);
        }
}
void DijkstraPQ(int p, int size)
{
        int i;
        for (i = 0; i < size; i++) {
                dist[i] = INT_MAX;
                prev[i] = -1;
        }
        dist[p] = 0;
        PQ_Init(size);
        while (heapsize > 0) {
                struct node *n;
                int u = heap[0];
                heap[0] = heap[heapsize - 1];
                heap_index[heap[size - 1]] = 0;
                heapsize--;
                downheap(0);
                for (n = list[u]; n != NULL; n = n->next) {
                        int w = n->weight, newlen = dist[u] + w;
                        if (newlen < dist[n->id]) {
                                dist[n->id] = newlen;
                                prev[n->id] = u;
                                upheap(heap_index[n->id]);
                        }
                }
        }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int weight[N_MAX][N_MAX];
int dis[N_MAX];

void set_shortest_distance(const int n) {
    bool ismember[n] = {false};

    int newmember = 0;
    dis[newmember] = 0;
    ismember[newmember] = true;

    FOR(t,0,n-1) {
        FOR(i,0,n) {
            if (weight[newmember][i] < 0) { continue; }
            if (ismember[i]) { continue; }
            const int d = dis[newmember] + weight[newmember][i];
            if (dis[i] < 0 || d < dis[i]) {
                dis[i] = d;
            }
        }
        int min_i = -1, min_d = -1;
        FOR(i,0,n) {
            if (dis[i] < 0) { continue; }
            if (ismember[i]) { continue; }
            if (min_d < 0 || dis[i] < min_d) {
                min_i = i;
                min_d = dis[i];
            }
        }
        newmember = min_i;
        ismember[newmember] = true;
        //cout << "#" << min_i << " " << min_d << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    FOR(i,0,n) {
        dis[i] = -1;
        FOR(j,0,n) {
            weight[i][j] = -1;
        }
    }

    int u, k, v, c;
    FOR(i,0,n) {
        cin >> u >> k;
        FOR(j,0,k) {
            cin >> v >> c;
            weight[u][v] = c;
        }
    }

    set_shortest_distance(n);

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

    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
int INF=1e+9+1;
int N,M[100][100];
int d[100],color[100],p[100];
void dijkstra(){
	int minv;
	rep(i,N){
		d[i]=INF;
		color[i]=0;
	}
	d[0]=0;
	color[0]=1;
	while(1){
		minv=INF;
		int u=-1;
		rep(i,N){
			if(minv>d[i]&&color[i]!=2){
				u=i;
				minv=d[i];
			}
		}
		if(u==-1) break;
		color[u]=2;
		rep(v,N){
			if(color[v]!=2&&M[u][v]!=INF){
				if(d[v]>d[u]+M[u][v]){
					d[v]=d[u]+M[u][v];
					color[v]=1;
				}
			}
		}
	}
}
int main(){
	scan(N);
	rep(i,N){
		rep(j,N){
			M[i][j]=INF;
		}
	}
	int k,c,u,v;
	rep(i,N){
		scan(u);scan(k);
		rep(j,k){
			scan(v);scan(c);
			M[u][v]=c;
		}
	}
	dijkstra();
	rep(i,N){
		printf("%d %d\n",i,(d[i]==INF ? -1 : d[i]));
	}
	return 0;
}