Go: package main

import (
	"fmt"
	"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)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		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})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include <iostream>

using namespace std;
int n;
int dat[100][100];
int cost[100];
int done[100];

void prim(){
	for(int i=0;i<n;i++){
		cost[i]=1<<21;
		done[i]=0;
	}
	int s=0;	
	int next, ncost=1<<21;
	done[s]=1;
	cost[s]=0;
	while(1){
		ncost=1<<21;
		for(int j=0;j<n;j++){
			if(done[j]){
				for(int i=0;i<n;i++){
					if(dat[j][i]!=-1){
						if(cost[i]>=dat[j][i]&&!done[i]){
							cost[i]=dat[j][i];
						}
						if(ncost>cost[i]&&!done[i]){
							next=i;
							ncost=cost[i];
						}
					}
				}
			}
		}
//		cout<<"next:"<<next<<" cost:"<<cost[next]<<endl;
		done[next]=1;
		int flag=true;
		for(int i=0;i<n;i++){
			if(!done[i]) flag = false;
		}
		if(flag)
			return;
	}
}


void dijk(){
	for(int i=0;i<n;i++){
		cost[i]=1<<21;
		done[i]=0;
	}
	int s=0;	
	int next, ncost=1<<21;
	done[s]=1;
	cost[s]=0;
	while(1){
		ncost=1<<21;
		for(int j=0;j<n;j++){
			if(done[j]){
				for(int i=0;i<n;i++){
					if(dat[j][i]!=0){
						if(cost[i]>=dat[j][i]+cost[j]){
							cost[i]=dat[j][i]+cost[j];
						}
						if(ncost>cost[i]&&!done[i]){
							next=i;
							ncost=cost[i];
						}
					}
				}
			}
		}
//		cout<<"next:"<<next<<" cost:"<<cost[next]<<endl;
		done[next]=1;
		int flag=true;
		for(int i=0;i<n;i++){
			if(!done[i]) flag = false;
		}
		if(flag)
			return;
	}
}


int main(){
	int num, from, dist, c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>from>>num;
		for(int j=0;j<num;j++){
			cin>>dist>>c;
			dat[from][dist]=c;
		}
	}
	dijk();
	for(int i=0;i<n;i++){
		cout<<i<<" "<<cost[i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int V;
int d[100001];
vector<edge> es[100001];

void dijkstra(int s)
{
	fill(d, d + V, INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		REP(i, es[v].size())
		{
			edge e = es[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	cin >> V;
	REP(i, V)
	{
		int u, k; cin >> u >> k;
		REP(i, k)
		{
			int c, v; cin >> v >> c;
			es[u].push_back(edge{ u, v, c });
		}
	}
	dijkstra(0);
	REP(i, V)
	{
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <queue>
using namespace std;

#define MAX_N (105)
#define MAX_D (100010)
#define INF (MAX_N * MAX_D)

int n;

int G[MAX_N][MAX_N];
int dist[MAX_N];
bool arrived[MAX_N];

void dijkstra(int s)
{
    for ( int i = 0; i < n; i++ ) dist[i] = INF;

    dist[s] = 0;

    while ( true ) {
	int min_dist = INF;
	int index = -1;
	for ( int i = 0; i < n; i++ ) {
	    if ( !arrived[i] && dist[i] < min_dist ) {
		min_dist = dist[i];
		index = i;
	    }
	}
	
	if ( index == -1 ) break;
	arrived[index] = true;

	for ( int i = 0; i < n; i++ ) {
	    if ( !arrived[i] && G[index][i] != INF ) {
		if ( dist[i] > (dist[index] + G[index][i]) ) {
		    dist[i] = dist[index] + G[index][i];
		}
	    }
	}
    }
}


int main()
{
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
	for ( int j = 0; j < n; j++ ) {
	    G[i][j] = INF;
	}
    }

    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);

	for ( int j = 0; j < k; j++ ) {
	    int v, c;
	    scanf("%d %d", &v, &c);
	    G[u][v] = c;
	}
    }

    dijkstra(0);

    for ( int i = 0; i < n; i++ ) {
	printf("%d %d\n", i, dist[i]);
    }

    return 0;
}

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

int n, adj_M[MAX][MAX];

void Dijkstra()
{
    int next, min_cost;
    int min_dist[n+1], color[n+1], parent[n+1];

    for (int i = 0; i < n; ++i) 
    {
        color[i]  = WHITE;
        parent[i] = -1;
        min_dist[i] = INF;
    }

    min_dist[0] = 0;

    while (true) 
    {
        min_cost = INF;
        next = -1;
        for (int i = 0; i < n; ++i) 
        {
            if (color[i] != BLACK && min_dist[i] < min_cost) 
            {
                min_cost = min_dist[i];
                next = i;
            }
        }
        if (next == -1) break;
        color[next] = BLACK;

        for (int i = 0; i < n; ++i) 
        {
            if (color[i] != BLACK && adj_M[next][i] != INF)
            {
                if (min_dist[next] + adj_M[next][i] < min_dist[i])
                {
                    color[i] = GRAY;
                    min_dist[i] = min_dist[next] + adj_M[next][i];
                    parent[i] = next;
                }
            }
        }
    }

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

int main() 
{
    int id, deg, n_id, n_w;
    cin >> n; 

    for (int i = 0; i < n; ++i) 
    {
        for (int j = 0; j < n; ++j) 
        {
            adj_M[i][j] = INF;
        }
    }

    for (int i = 0; i < n; ++i) 
    {
        cin >> id >> deg;
        for (int j = 0; j < deg; ++j) 
        {
            cin >> n_id >> n_w;
            adj_M[id][n_id] = n_w;
        }
    }

    Dijkstra();
}