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>
#include <vector>
#include <queue>
#define INF 1000000
using namespace std;

class vertex{
public:
  class edge{
  public:
    int to;
    int weight;
    edge(int to, int weight){
      this->to = to;
      this->weight = weight;
    }
  };

  vector<edge> edges;
  int num;
  int dis;

  vertex(){
    n++;
    vertexes.push_back(this);
  }

  bool operator< (const vertex& v) const{
    return dis < v.dis;
  }

  bool operator> (const vertex& v) const{
    return dis > v.dis;
  }

  static void dijkstra(int start){
    //距離の初期化
    for(int i=0; i<n; i++) vertexes[i]->dis=INF;
    vertexes[start]->dis=0;

    //プライオリティキューを初期化、始点を格納
    priority_queue<vertex, vector<vertex>, greater<vertex> > pq; pq.push(*vertexes[start]);


    while(!pq.empty()){
      vertex now = pq.top(); pq.pop(); //キューの先頭をポップ
      if(now.dis>vertexes[now.num]->dis) continue;

      //ポップしたキューの頂点集合について最短距離更新
      for(int i=0; i<now.edges.size(); i++){
        int newDis = now.dis+now.edges[i].weight;
        vertex* next = vertexes[now.edges[i].to];
        if(newDis < next->dis){
          next->dis = newDis;
          pq.push(*next);
        }
      }

    }


  }

  static void print(){
    for(int i=0; i<n; i++){
      cout << vertexes[i]->num << " " << vertexes[i]->dis << endl;
    }
  }
private:
  static int n;
  static vector<vertex*> vertexes;
};

int vertex::n=0;
vector<vertex*> vertex::vertexes;

int main(){
  int n; cin >> n;

  vertex graph[n];

  //入力を隣接リストのようなものに格納
  int v, k, to, weight;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[i].num=v;
    for(int j=0; j<k; j++){
      cin >> to >> weight;
      vertex::edge e(to, weight);
      graph[v].edges.push_back(e);
    }
  }

  vertex::dijkstra(0); //0始点のダイクストラ法

  vertex::print();

  return 0;
}

C++: #include <stdio.h>
static const int MAX=100;
static const int INFTY=(1<<30);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];

void dijkstra(){
    int minv,i,o;
    int d[MAX],color[MAX];
    for(i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)
            break;
        color[u]=BLACK;
        for(o=0;o<n;o++){
            if(color[o]!= BLACK && M[u][o] != INFTY){
                if(d[o]>d[u]+M[u][o]){
                    d[o]=d[u]+M[u][o];
                    color[o]=GRAY;
                }
            }
        }
    }
    for(i=0;i<n;i++)
        printf("%d %d\n",i,(d[i]==INFTY)?-1:d[i]);
}

int main(void){
    int i,o,k,c,u,v;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        for(o=0;o<n;o++)
            M[i][o]=INFTY;
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(o=0;o<k;o++){
            scanf("%d %d",&v,&c);
            M[u][v]=c;
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
const int inf=1e9;
using namespace std;
int main(){

  int n,now=0;
  priority_queue < pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > g[100000];
  cin>>n;
  for(int i=0,u,k,v,c;i<n&&cin>>u>>k;i++) for(int j=0;j<k&&cin>>v>>c;j++) g[u].push(make_pair(c,v));
  int flag[100]={},c[100]={};
  for(int i=1;i<n;i++) c[i]=inf;
  for(int i=0;i<n-1;i++){
    int next=g[now].top().second;
    for(;!g[now].empty();g[now].pop()) if(!flag[g[now].top().second]) c[g[now].top().second]=min(c[g[now].top().second],c[now]+g[now].top().first);
    flag[now]=1;
    now=next;
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<c[i]<<endl;
  return 0;

}

C++: #include <iostream>
 using namespace std;
 static const int WHITE = 0;
 static const int GRAY = 1;
 static const int BLACK =2;
 static const int MAX = 100;
 static const int INFTY = (1<<21);
 
 int n,M[MAX][MAX];
 
 void dijks(){
 	int minv;
 	int d[MAX];
 	int color[MAX];
 	for(int i=0;i<n;i++){
 		d[i] = INFTY;
 		color[i] = WHITE;
 	}
 	
 	d[0] = 0;
 	color[0] = GRAY;
 	while(1){
 		minv = INFTY;
 		int u=-1;
 		for(int i=0;i<n;i++){
 			if(color[i]!=BLACK&&d[i]<minv){
 				minv = d[i];
 				u=i;
 			}
 		}
 		
 		if(u==-1) break;
 		
 		color[u] = BLACK;
 		
 		for(int v=0;v<n;v++){
 			if(color[v]!=BLACK&&M[u][v]<INFTY){
 				if(d[v]>d[u]+M[u][v]){
 					d[v] = d[u]+M[u][v];
 					color[v] = GRAY;
 				}
 			}
 		}
 	}
 	
 	for(int i=0;i<n;i++){
 		cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
 	}
 }
 
 int main(){
 	cin>>n;
 	
 	for(int i=0;i<n;i++){
 		for(int j=0;j<n;j++){
 			M[i][j] = INFTY;
 		}
 	}
 	
 	int k,u,c,v;
 	for(int i=0;i<n;i++){
 		cin>>u>>k;
 		for(int j=0;j<k;j++){
 			cin>>c>>v;
 			M[u][c] = v;
 		}
 	}
 	dijks();
 	return 0;
 }