Go: package main

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

const (
	MAX_N      = 10000
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

type Neighbor struct {
	node   int
	weight int
}

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

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]Neighbor, error) {
	adjacentMatrix := make([][]Neighbor, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = []Neighbor{}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id] = append(adjacentMatrix[id], Neighbor{v, c})
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]Neighbor) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]Neighbor) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for _, neighbor := range adjacents {
		edges = append(edges, Edge{start: currentNode, end: neighbor.node, weight: neighbor.weight})
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int MAX = 10000;
const int INF = 1e9 + 7;

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

void dijkstra()
{
  int d[MAX], color[MAX];
  priority_queue<pair<int, int> > pq;

  fill(d, d + MAX, INF);
  fill(color, color + MAX, 0);

  d[0] = 0;
  pq.push(make_pair(0, 0));
  color[0] = 1;

  while (!pq.empty()) {
    pair<int, int> f = pq.top();
    pq.pop();
    int u = f.second;
    color[u] = 2;

    if (d[u] < f.first * (-1)) continue;
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == 2) continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        pq.push(make_pair(d[v] * (-1), v));
        color[v] = 1;
      }
    }
  }
  
  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

signed main()
{
  int u, k, c, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return (0);
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
using namespace std;

#define NIL -1
#define INF 100000000
#define WHITE 1
#define GREY 2
#define BLACK 3
#define N_MAX 100

int G[N_MAX][N_MAX];
int V[N_MAX];
int V_value[N_MAX];

void init(){
    for(int i = 0; i < N_MAX; i++){
        V[i] = WHITE;
        V_value[i] = INF;
    }

    for(int i = 0; i < N_MAX; i++){
        for(int j = 0; j < N_MAX; j++){
            G[i][j] = NIL;
        }
    }
}

int main(void){
    init();
    int n;
    scanf("%d\n", &n);

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

    priority_queue<pair<int, int>> PQ;

    V[0] = BLACK;
    V_value[0] = 0;
    int new_node = 0;
    
    while(1){
        //printf("new_node: %d\n", new_node);
        for(int i = 0; i < n; i++){
            if(G[new_node][i] != NIL && V[i] == WHITE){
                V_value[i] = min(V_value[i], V_value[new_node] + G[new_node][i]);
                //printf("push %d %d\n",i,  V_value[i]);
                PQ.push(make_pair(V_value[i] * (-1), i));
            }
        }

        int min_value;
        int min_index = NIL;
        while(!PQ.empty()){
            pair<int, int> p = PQ.top(); PQ.pop();
            //printf("pop %d %d\n", p.second, p.first * (-1));
            if(p.first * (-1) == V_value[p.second] && V[p.second] == WHITE){
                min_value = p.first * (-1);
                min_index = p.second;
                break;
            }
        }

        if(min_index == NIL)
            break;

        new_node = min_index;
        V[new_node] = BLACK;
        V_value[new_node] = min_value;
    }
    
    for(int i = 0; i < n; i++){
        printf("%d %d\n", i, V_value[i]);
    }

    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

static const int MAX_NUM = 10000;
enum eState {
    NO_VISIT = 0,
    NOW_VISIT,
    END_VISIT
};

void SSSP(vector<pair<int, int> > matrix[], int num)
{
    int i;
    int cost[MAX_NUM];
    eState state[MAX_NUM] = {NO_VISIT};
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;

    for (i = 0; i < num; i++) {
        cost[i] = 100000 * MAX_NUM;
    }

    PQ.push(make_pair(0, 0));
    cost[0]  = 0;
    state[0] = NOW_VISIT;

    while (PQ.empty() == false) {
        int tid;
        int nid, ncost;
        pair<int, int> target = PQ.top();
        PQ.pop();

        tid = target.second;
        state[tid] = END_VISIT;

#if 0
        if (cost[tid] < target.second) {
            continue;
        }
#endif

        for (i = 0; i < matrix[tid].size(); i++) {
            nid   = matrix[tid][i].second;
            ncost = matrix[tid][i].first;
            if ((state[nid] != END_VISIT) && (cost[nid] > (ncost + cost[tid]))) {
                cost[nid]  = ncost + cost[tid];
                state[nid] = NOW_VISIT;
                PQ.push(make_pair(cost[nid], nid));
            }
        }
    }

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

    return;
}

int main(void)
{
    int i, j;
    int num;
    int target, pathnum;
    int path, cost;
    vector<pair<int, int> > matrix[MAX_NUM];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d %d", &target, &pathnum);
        for (j = 0; j < pathnum; j++) {
            scanf("%d %d", &path, &cost);
            matrix[target].push_back(make_pair(cost, path));
        }
    }

    SSSP(matrix, num);

    return 0;
}