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 <stdio.h>
#include <vector>

using namespace std;

struct Wside{
	int vertex;
	int weight;
	Wside(int a, int b){
		vertex=a; weight=b;
	}
};

vector<Wside>* info;
vector<int> scanned;
int* result, *candidates;
int n;

bool isScanned(int v){
	for(int i=0,sz=scanned.size(); i<sz; ++i){
		if(v==scanned[i]) return 1;
	}
	return 0;
}

int scan(){
	int nextvtx;
	for(int j=0, scn=scanned[scanned.size()-1], sz=info[scn].size(); j<sz; ++j){
		int vtx = info[scn][j].vertex;
		if(isScanned(vtx)) continue;
		int wgh = info[scn][j].weight;

		result[vtx] = result[vtx] > result[scn] + wgh ? (result[scn] + wgh) : result[vtx];
		candidates[vtx] = result[vtx];
	}

	int minimum=0xfffffff;
	for(int i=0; i<n; ++i){
		if(candidates[i]==-1) continue;
		nextvtx = minimum<candidates[i]? nextvtx : i;
		minimum = result[nextvtx];
	}
	candidates[nextvtx]=-1;
	scanned.push_back(nextvtx);
	return 0;
}

int main()
{
	scanf("%d",&n);
	scanned.reserve(n);
	info = new vector<Wside> [n];
	result = new int [n];
	candidates = new int [n];
	for(int i=0; i<n; ++i){
		result[i] = 0xfffffff;
		candidates[i] = -1;
	}

	int org,k,v,c;
	for(int i=0; i<n; ++i){
		scanf("%d %d",&org,&k);
		info[org].reserve(k);
		for(int j=0; j<k; ++j){
			scanf("%d %d",&v,&c);
			info[org].push_back(Wside(v,c));
		}
	}

	scanned.push_back(0);
	result[0] = 0;
	while(scanned.size()!=n){
		scan();
	}

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

	delete[] info;
	delete[] result;
	delete[] candidates;

	return 0;
}

C++: // ALDS1_12_C: Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#define NIL -1
#define INF 1000000
using intpair = std::pair<int,int>;
bool debug = false;

std::vector<std::vector<intpair>> adjacency_list; // pair = (vertex_num, weight)
std::vector<bool> node_stat;
std::vector<int> minimum_cost;
std::priority_queue<intpair, std::vector<intpair>, std::greater<intpair>> que; // pair = (weight, vetrex_num)

void dijkstra(int vertex) {
    if (debug) std::cout << "dijkstra(" << vertex << ")\n";
    // 1. mark as visited
    node_stat.at(vertex) = false;

    // 2. push weights into priority queue.
    for (int i=0; i<adjacency_list.at(vertex).size(); i++) {
        int next = adjacency_list.at(vertex).at(i).first;
        int edge_weight = adjacency_list.at(vertex).at(i).second;
        int weight = minimum_cost.at(vertex) + edge_weight;

        if (debug) std::cout << "next = " << next << ", weight = " << weight << "\n";
        intpair tmp = std::make_pair(weight, next);
        que.push(tmp);
    }

    // 3. get appropriate next_vertex and determine minimum_cost(next_vertex)
    int next = NIL;
    int size = que.size(); // do NOT use .size() when it can change!!!!!!
    for (int i=0; i<size; i++) {
        int cost = que.top().first, next_vertex = que.top().second;
        que.pop(); 
        if (node_stat.at(next_vertex)) {
            if (cost < minimum_cost.at(next_vertex)) {
                minimum_cost.at(next_vertex) = cost;
                next = next_vertex;
                break;
            }
        }
    }
    // 4. end of recursion
    if (next == NIL) return;

    // 5. recurving
    dijkstra(next);
}

int main() {
    int total_node_num; std::cin >> total_node_num;
    adjacency_list.resize(total_node_num);
    node_stat.assign(total_node_num, true);
    minimum_cost.assign(total_node_num, INF);
    minimum_cost.at(0) = 0;

    for (int i=0; i<total_node_num; i++) {
        int vertex, outdegree; std::cin >> vertex >> outdegree;
        for (int j=0; j<outdegree; j++) {
            std::pair<int,int> tmp; std::cin >> tmp.first >> tmp.second;
            adjacency_list.at(vertex).push_back(tmp);
        }
    }

    dijkstra(0);
    for (int i=0; i<minimum_cost.size(); i++) {
        std::cout << i << " " << minimum_cost.at(i) << "\n";
    }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000
#define EMAX 500000
#define INFTY 2000000000
typedef struct {
  int pre,next,x;
}Cost;
int n,d[MAX];
Cost E[EMAX];
void jr(int);

void jr(int cou){
  int i,tmp;

  for(i=0;i<n;i++){
    d[i]=INFTY;
  }

  d[0]=0;

  tmp=1;
  while(tmp!=0){
    tmp=0;
    for(i=0;i<cou;i++){
      if(E[i].x+d[E[i].pre]<d[E[i].next]){
	d[E[i].next]=E[i].x+d[E[i].pre];
	tmp=1;
      }
    }
  }
}

int main()
{
  int n,i,j,u,k,v,cou=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      E[cou].pre=u;
      scanf("%d %d",&E[cou].next,&E[cou].x);
      cou++;
    }
  }

  jr(cou);

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

  return 0;
}