Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

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