Go: package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := make(map[int]int)
	q[0] = 0
	visited := make(map[int]struct{})
	out := make([]int, n)

	for len(q) > 0 {
		u := top(q)
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			if d, ok := q[uu]; !ok || d > q[u]+c {
				q[uu] = q[u] + c
			}
		}

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <string.h>

using namespace std;
static const int INF = 1e9;
typedef pair<int, int> P;
struct edge
{
	int to;
	int cost;
};

int d[101];
vector<edge> G[101];

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			int to, cost;
			cin >> to >> cost;
			edge e1;
			e1.to = to;
			e1.cost = cost;
			G[u].push_back(e1);
		}
	}
	for (int i = 0; i < 101; ++i)
	{
		d[i] = INF;
	}
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P> > pque;
	pque.push(P(0, 0));
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int v = p.second;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				pque.push(P(d[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << i << " " << d[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INF=(1<<21);
static const int WH=0;
static const int GRY=1;
static const int BL=2;

int n, MA[MAX][MAX];

void DijkStra(){
  int minV;
  int d[MAX], color[MAX];

  for(int i=0; i<n; i++)
  {
    d[i]=INF;
    color[i]=WH;
  }

  d[0]=0;
  color[0]=GRY;

  while(1)
  {
    minV=INF;
    int u = -1;
    for(int i=0; i<n; i++)
    {
      if(minV > d[i] && color[i] != BL)
      {
        u=i;
        minV=d[i];
      }
    }
    if(u == -1) break;
    color[u]=BL;
    for(int v=0; v<n; v++)
    {
      if(color[v] != BL && MA[u][v] != INF)
      {
        if(d[v] > d[u] + MA[u][v])
        {
          d[v]=d[u]+MA[u][v];
          color[v]=GRY;
        }
      }
    }
  }

  for(int i=0; i<n; i++)
  {
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

int main(){
  cin >> n;
  for(int i=0; i<n; i++)
  {
    for(int j=0; j<n; j++)
    {
      MA[i][j]=INF;
    }
  }

  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;
      MA[u][v]=c;
    }
  }

  DijkStra();

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,M[105][105];
void djkstr(){
  int minv;
  int d[105],color[105];

  for(int i=0;i<n;i++){
    d[i]= 1234567890;
    color[i]=0;
  }
  d[0]=0;
  color[0]=1;
  while(1){
    minv = 1234567890;
    int u = -1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=2){
	u=i;
	minv = d[i];
      }
    }
    if(u==-1)break;
    color[u]=2;
    for(int v=0;v<n;v++){
      if(color[v]!=2&&M[u][v]!=1234567890){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=1;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i << " " << (d[i]==1234567890?-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]=1234567890;
    }
  }
  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;
    }
  }
  djkstr();
  return 0;
}

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;
      cout << "now" << now.num << " " << now.dis << endl;

      //ポップしたキューの頂点集合について最短距離更新
      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 <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 1e4 + 7, INF = 5e5 + 7;
int d[MAXN];
struct node {
	int id, dist;
	node(int id, int dist) :id(id), dist(dist) {}
	bool operator < (const node &rhs) const {
		return dist > rhs.dist;
	}
};
vector<pair<int, int> > G[MAXN];
priority_queue<node> nodes;
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
    	d[i] = 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].push_back(make_pair(v, c));
		}
	}
	nodes.push(node(0, 0));
	while (!nodes.empty()) {
		node tmp = nodes.top();
		nodes.pop();
		if (tmp.dist > d[tmp.id]) continue;
		int cnt = G[tmp.id].size();
		for (int i = 0; i < cnt; i++) {
			if (d[G[tmp.id][i].first] > d[tmp.id] + G[tmp.id][i].second) {
				d[G[tmp.id][i].first] = d[tmp.id] + G[tmp.id][i].second;
				nodes.push(node(G[tmp.id][i].first, d[G[tmp.id][i].first]));
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d %d\n", i, d[i]);
	}
	return 0;
}