Go: package main

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

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

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

C++: #include<stdio.h>
#define inf 1000000010
int v[10001][10001];
int a[10001][10001];
int d[10001];
int pi[10001];
char color[10001];
int n,mincost;
int k[10001];

void dijkstra(void);

int main(){
  int i,j,u;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=inf;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d" ,&u,&k[i]);      
  for(j=1;j<=k[i];j++){
     scanf("%d",&v[u][j]);
     scanf("%d",&a[u][v[u][j]]);   
    }
  }
  dijkstra();

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

  return 0;
}

void dijkstra(void){
  int i,j,u,min;
  
  for(i=0;i<n;i++){
    d[i]=inf;
    pi[i] = -1;
    color[i]='W';
  }
  d[0]=0;
  while(1){
    mincost = inf;
    for(i=0;i<n;i++){
      if(color[i]!='B' && d[i] < mincost){
	mincost = d[i];
        u = i;
      }
    }
    if(mincost==inf) break;
    color[u]='B';
  
  for(i=0;i<n;i++){
    if(color[i]!='B' && a[u][i]!=inf  && d[u]+a[u][i]<d[i]){
      pi[i] = u;
      d[i]=d[u]+a[u][i];
     }
   }
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define llong long long 
typedef pair<long int, int> P;
long int d[10001];
bool Dec[10001];
vector<P> edges[10001];
priority_queue<P, vector<P>, greater<P> > q;

void solve(){
	fill_n(d, 10001, 9999999);
	d[0] = 0;
	fill_n(Dec, 10001, false);
	q.push(P(0,0));

	while(!q.empty()){
		P p = q.top(); q.pop();
		if(Dec[p.second] == true) continue;
		Dec[p.second] = true;
		d[p.second] = p.first;

		for(int i = 0; i < edges[p.second].size(); i++){
			P e = edges[p.second][i];
			if(d[e.second] > p.first + e.first){
				q.push(P(p.first + e.first, e.second));
			}
		}
	}

	return;
}

int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int num;
		int howedge;
		cin >> num >> howedge;
		for(int j = 0; j < howedge; j++){
			int to;
			long int cost;
			cin >> to >> cost;
			edges[num].push_back(P(cost, to));
		}
	}

	solve();

	for(int i = 0; i < N; i++){
		cout << i << " " << d[i] << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#define INF 999999

int n, k;
int color[30000], d[30000];
int map[30000][30000];

int dijkstra(int s)
{
    for(int i = 0; i < n; i ++)
    {
        d[i] = INF;
    }
    d[s] = 0;
    while(1)
    {
        int min = INF;
        int u = -1;
        for(int i = 0; i < n; i ++)
        {
            if(min > d[i] && color[i] != 1)
            {
                u = i;
                min = d[i];
            }
        }
        if(u == -1)
            break;
        color[u] = 1;//染色，以防后面重复使用
        for(int i = 0; i < n; i ++)
        {
            if(color[i] != 1 && map[u][i] != INF)
                if(d[i] > d[u] + map[u][i])
                    d[i] = d[u] + map[u][i];
        }
    }
    return 0;
}

int main(void)
{
    int x, y, v;
    scanf("%d", &n);
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            map[i][j] = INF;
    for(int i = 0; i < n; i ++)
    {
        scanf("%d%d", &x, &k);
        for(int j = 0; j < k; j ++)
        {
            scanf("%d%d", &y, &v);
            map[x][y] = v;
        }
    }
    dijkstra(0);
    
    for(int i = 0; i < n; i ++)
    {
        if(d[i] != INF)
            printf("%d %d", i, d[i]);
        printf("\n");
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

static const int MAX = 100000;
static const int BLACK = -1;
static const int WHITE = 0;
static const int GLAY = 1;
static const int INFTY = 1e9;

int n;
vector<pair<int, int>> adj[MAX];

void pdai(){
	priority_queue<pair<int, int>> PQ;
	int d[MAX];
	int color[MAX];
	rep(i, n){
		d[i] = INFTY;
		color[i] = WHITE;
	}
	PQ.push(make_pair(0, 0));
	color[0] = GLAY;
	d[0] = 0;
	while(!PQ.empty()){
		pair<int, int> f = PQ.top();PQ.pop();
		int u = f.second;
		color[u] = BLACK;
		if(d[u] < f.first*(-1)) continue;
		for(int i = 0; i < adj[u].size(); i++){
			int v = adj[u][i].first;
			if(color[v] != BLACK && d[v] > d[u] + adj[u][i].second){
				d[v] = d[u] + adj[u][i].second;
				PQ.push(make_pair(d[v]*(-1), v));
				color[v] = GLAY;
			}
		}
	}
	rep(i, n){
		if(d[i] == INFTY) d[i] = -1;
		cout << i << " " << d[i] << endl;
	}
}

int main(){
	cin >> n;
	int u, k, v, c;
	rep(i, n){
		cin >> u >> k;
		rep(j, k){
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}
	pdai();
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define INF 1e9
using namespace std;

int main(){
    //declaration and input
    int n;
    cin >> n;
    int u, k;
    vector<vector<pair<int, int>>> graph(n);
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            graph[u].push_back(make_pair(c, v));
        }
    }
    vector<int> cost(n, INF);
    vector<bool> is_visit(n, false);
    vector<int> parent_of(n, -1);

    //dijkstra
    //init
    cost[0] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    que.push(make_pair(0, 0));

    //loop
    while (!que.empty()){
        pair<int, int> p = que.top();
        que.pop();
        int c = p.first; //cost
        int v = p.second; //vertax
        is_visit[v] = true;
        if (c > cost[v])
            continue;
        for (int i = 0; i < graph[v].size(); i++){
            if (!is_visit[graph[v][i].second]){
                if (cost[v] + graph[v][i].first < cost[graph[v][i].second]){
                    cost[graph[v][i].second] = cost[v] + graph[v][i].first;
                    que.push(make_pair(cost[graph[v][i].second], graph[v][i].second));
                    parent_of[graph[v][i].second] = v;
                }
            }
        }
    }

    //output
    for (int i = 0; i < n; i++){
        cout << i << ' ' << cost[i] << endl;
    }
    return 0;
}