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;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

struct Node{int color, dist, parent;};

int M[MAX][MAX], n;
Node node[MAX];

int main(){
  cin >> n;

  //initialize M and node
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      M[i][j] = INFTY;
    }
    node[i].color = WHITE;
    node[i].dist = INFTY;
    node[i].parent = -1;
  }

  //input distances
  for(int i = 0; i < n; i++){
    int u, k, v, c;
    cin >> u >> k;
    while(k--){
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  int p = 0, min_dis;
  node[p].dist = 0;
  node[p].color = BLACK;

  while(true){
    for(int i = 0; i < n; i++){
      if(M[p][i] != INFTY && node[i].color != BLACK){
        int d = node[p].dist + M[p][i];
        if(node[i].dist > d){
          node[i].dist = d;
          node[i].color = GRAY;
          node[i].parent = p;
        }
      }
    }

    p = -1;
    min_dis = INFTY;
    for(int i = 0; i < n; i++){
      if(node[i].color == GRAY && node[i].dist < min_dis){
        p = i;
        min_dis = node[i].dist;
      }
    }

    if(p == -1)
      break;

    node[p].color = BLACK;
  }

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

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;
	
const long long INF = 7+(1e+18);
typedef long long Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 g:隣接リスト,s:始点,dist:各頂点までの距離が入る,prev:最短路木の親頂点が入る
//戻値 なし
void shortestPath(const Graph &g,int s,vector<Weight> &dist,vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;
  Q.push(Edge(-2, s, 0));
  while(!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto f=g[e.dst].begin();f!=g[e.dst].end();f++){
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
//-----------------
int main()
{ 
    while(true){
        int i, j, k, V;
        int u, v;
        Weight c;
        if(!(cin >> V))break;
        Graph g(V);    //頂点数vの空隣接リストgを生成
        for(i=0; i<V; i++){
            cin >> u >> k;
            for(j=0; j<k; j++){
                cin >> v >> c;
                g[u].push_back(Edge(u, v, c));    //隣接リストgにsからtに向かう重さwの辺を追加
            }
        }
        vector<Weight> dist;
        vector<int> prev;
        shortestPath(g,0,dist,prev);
        for(i=0; i<V; i++){
            cout << i << " " << dist[i] << endl;
        }
    }
  
    return 0;
}

C++: #include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#define INF 100000000
#define ll long long
using namespace std;
int main(){
  int n;
  cin >> n;
  vector< vector< pair<int,int> > > edges(n);
  for(int i = 0; i < n; i++){
    int id = 0;
    cin >> id;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v, c;
      cin >> v >> c;
      edges[id].push_back(make_pair(v,c));
    }
  }

  priority_queue< pair<int,int>, vector< pair<int,int> > , less< pair<int,int> > > pq;
  pq.push(make_pair(0,0));
  vector<long long> dist(n, INF);
  dist[0] = 0;
  while(!pq.empty()){
    ll source = pq.top().second;
    pq.pop();
    for(pair<int,int> edge: edges[source]){
      if(dist[edge.first] > dist[source] + edge.second){
	dist[edge.first] = dist[source] + edge.second;
	pq.push(make_pair(dist[edge.first], edge.first));
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << i << ' ';
    cout << dist[i] << endl;
  }
}

C++: #include <map>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int n=0,N,i,j,k,c;
	scanf("%d",&N);
	vector<map<int,int> >dist(N);
	vector<bool>used(N);
	vector<int>cost(N);
	for(;n<N;n++){
		cost[n]=9999999;
		for(scanf("%d%d",&i,&k);k--;dist[j][i]=c)scanf("%d%d",&j,&c); //i->j cost c
	}
	for(cost[0]=0;;){ //dijkstra
		int m=9999999;
		for(i=0;i<N;i++)if(!used[i]&&m>cost[i])m=cost[i];
		if(m==9999999)break;
		for(j=0;j<n;j++)if(m==cost[j]){
			map<int,int>::iterator it=dist[j].begin();
			for(used[j]=1;it!=dist[j].end();it++)if(cost[it->first]>it->second+cost[j])cost[it->first]=it->second+cost[j];
		}
	}
	for(i=0;i<n;i++)printf("%d %d\n",i,cost[i]);
}

C++: #include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],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(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[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,c,u,v;
    for (int i = 0; i < n; ++i) {
        cin>>u>>k;
        for (int j = 0; j < k; ++j) {
            cin>>v>>c;
            M[u][v]=c;
        }
    }

    dijkstra();

    return 0;
}