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
}

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) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		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][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	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 [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for i, v := range adjacents {
		if v >= 0 {
			edges = append(edges, Edge{start: currentNode, end: i, weight: v})
		}
	}
	return edges
}

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

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
string u="abcdefghijklmnopqrstuvwxyz";

struct edge {int to;LL cost;};

const int M_N=10000;

vector<edge> G[M_N+1];
LL d[M_N+1];

struct Dijkstra{

    void dijkstra(int s){
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }

};

int main(){
    Dijkstra Ds;
    fill(d,d+M_N+1,LINF);
    d[0]=0;
    int N;
    cin >> N;
    int u,k,v,c;
    while(cin >> u >> k){
        for(int i=0;i<k;i++){
            cin >> v >> c;
            G[u].push_back({v,c});
        }
    }
    Ds.dijkstra(0);
    for(int i=0;i<N;i++){
        cout << i <<" "<< d[i] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define max 10000
#define infty 1<<21

int n;
int d[max];
int color[max];
vector<vector<int> > v(max);

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < v[x].size() / 2; i++) {
				if (d[x] +v[x][(2 * i) + 1] < d[v[x][2 * i]]) {
					d[v[x][2 * i]] = d[x] + v[x][(2 * i) + 1];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			v[id].push_back(num1);
			v[id].push_back(kyori);
		}
	}

	soya();

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

	return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#define N 10001
#define INF 1000000009
using namespace std;

struct Heap{
  int key,cost;
};

struct node{
  int key,cost;
  node *prev,*next;
};

node *nil[N];
int n,d[N];
Heap A[N];

void init(){
  for(int i=0;i<n;i++){
  nil[i] = (node *)malloc(sizeof(node));
  nil[i]->next =nil[i];
  nil[i]->prev=nil[i];
  }
}

void insert(int i,int key,int cost){
  node *x= (node *)malloc(sizeof(node));
  x->key = key,x->cost=cost;
  x->next = nil[i]->next;
  nil[i]->next->prev = x;
  nil[i]->next = x;
  x->prev = nil[i];
}

int size;
void increase(int i,int key,int cost){
  Heap tmp;
  A[i].key=key,A[i].cost=cost;
  while(i>1 && A[i/2].cost > A[i].cost)tmp=A[i],A[i]=A[i/2],A[i/2]=tmp,i=i/2;
}

void insert(int key,int cost){
  size++,A[size].key=INF,A[size].cost=INF;
  increase(size,key,cost);
  }

void minHeapify(int i){
  int l,r,min;
  Heap tmp;
 l=i*2;
  r=i*2+1;
  if(l<=size && A[l].cost<A[i].cost)min=l;
  else min=i;
  if(r<=size && A[r].cost<A[min].cost)min=r;
  if(min!=i){tmp=A[i],A[i]=A[min],A[min]=tmp; minHeapify(min);}
}


Heap extractMin(){
  Heap min;
  min=A[1],A[1]=A[size],size--,minHeapify(1);
  return min;
}

void dijkstra(int s){
  Heap u;
  int used[N];
  for(int i=0;i<n;i++) used[i]=0,d[i]=INF;
  d[s]=0;
  while(size>=1){
    u=extractMin();
    used[u.key]=2;
    if(d[u.key] <u.cost)continue;
    node *v=nil[u.key]->next;
    while(v!=nil[u.key]){
      if(used[v->key]!=2)
	if(d[u.key]+v->cost<d[v->key])
	  d[v->key]=d[u.key]+v->cost,used[v->key]=1,insert(v->key,d[v->key]);
      v=v->next;
  }
}
}

int main(){
  cin>>n;
  init();
  int u,k,v,c;
  size=n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      insert(u,v,c);
    }
  }
  dijkstra(0);
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  
  return 0;
}