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++: /*
 ********************************************************************************
 *  Author: ThoseBygones
 *  Version: V1.0
 *  Date: 2018-06-27
 *  Subject: ACM-ICPC
 *  Language: C/C++11
 *  OJ: AOJ
 *  Algorithm: 最短路Dijkstra
 ********************************************************************************
 *  Algo-Description:
 ********************************************************************************
 */

//#include <bits/stdc++.h>  //For CodeForces only

//#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x)
{
    return x * x;
}
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
#define forIt(mp,it) for(__typeof(mp.begin()) it = mp.begin();it!=mp.end();it++)
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0);

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lowbit(u) (u&(-u))
#define MAXN 105
#define MAXE (MAXN*MAXN)>>1

typedef int Type;

class Dijkstra
{
public:
    int head[MAXN],nxt[MAXE],cnt;
    Type d[MAXN];
    struct Edge
    {
        int v;
        Type cost;
        Edge() {}
        Edge(int v,Type cost):v(v),cost(cost) {}
        bool operator<(const Edge& ed) const
        {
            return cost>ed.cost;
        }
    } e[MAXE];
    bool vis[MAXN];

    //初始化，n为点数
    void init(int n)
    {
        cnt = 0;
        for(int i = 0; i<n; i++)
            head[i] = -1;
    }

    inline void addEdge(int u,int v,Type cost)
    {
        e[cnt] = Edge(v,cost);
        int tmp = head[u];
        head[u] = cnt;
        nxt[cnt++] = tmp;
    }

    Type dijkstra(int s,int t,int n)
    {
        for(int i = 0; i<n; i++)
            d[i] = INF,vis[i] = false;
        d[s] = 0;
        priority_queue<Edge> q;
        q.push(Edge(s,0));
        while(!q.empty())
        {
            Edge ed = q.top();
            q.pop();
            vis[ed.v] = true;
            if(ed.v==t) //如果未给出终点t，则完全可以不要跟t有关的语句
                return d[t];
            for(int i = head[ed.v]; ~i; i = nxt[i])
            {
                Edge ee = e[i];
                if(!vis[ee.v]&&d[ee.v]>d[ed.v]+ee.cost)
                {
                    d[ee.v] = d[ed.v]+ee.cost;
                    /*
                     *  最短路树
                    	p[ee.v] = MP(u,i);
                    */
                    q.push(Edge(ee.v,d[ee.v]));
                }
            }
        }
        return d[t];
    }

    void buildGraph(int n)
    {
        for(int i=0; i<n; i++)
        {
            int u,num;
            scanf("%d%d",&u,&num);
            while(num--)
            {
                int v,w;
                scanf("%d%d",&v,&w);
                addEdge(u,v,w);
            }
        }
    }
} dij;

int main()
{
    int n;
    scanf("%d",&n);
    dij.init(n);
    dij.buildGraph(n);
    for(int i=0; i<n; i++)
        printf("%d %d\n",i,dij.dijkstra(0,i,n));
    return 0;
}

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];

int 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;
    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;
}

C++: #include <iostream>
#include <limits.h>
#include <vector>

using namespace std;

struct Node {
    int cost = INT_MAX;
    int color = 0;
    vector<int> next_node;
    vector<int> len_cost;
} node[100];

int main() {
    int n, id, k;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        node[id].next_node.resize(k);
        node[id].len_cost.resize(k);
        for (int j = 0; j < k; j++) {
            cin >> node[id].next_node[j] >> node[id].len_cost[j];
        }
    }

    int size1, size2;
    vector<int> vec;
    node[0].cost = 0;
    node[0].color = 1;
    vec.push_back(0);
    while (1) {
        size1 = vec.size();
        if (size1 == n) {
            break;
        }
        for (int i = 0; i < size1; i++) {
            size2 = node[vec[i]].next_node.size();
            for (int j = 0; j < size2; j++) {
                if (node[node[vec[i]].next_node[j]].cost > node[vec[i]].cost + node[vec[i]].len_cost[j]) {
                    node[node[vec[i]].next_node[j]].cost = node[vec[i]].cost + node[vec[i]].len_cost[j];
                }
            }
        }
        int min = INT_MAX, mini;
        for (int i = 0; i < size1; i++) {
            size2 = node[vec[i]].next_node.size();
            for (int j = 0; j < size2; j++) {
                if (min > node[node[vec[i]].next_node[j]].cost && node[node[vec[i]].next_node[j]].color == 0) {
                    min = node[node[vec[i]].next_node[j]].cost;
                    mini = node[vec[i]].next_node[j];
                }
            }
        }
        vec.push_back(mini);
        node[mini].color = 1;
    }

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