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

using namespace std;

#define MAX 10000
#define INFINITY 300000

int n;
int color[MAX], d[MAX];

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

enum Color {
    WHITE,
    GRAY,
    BLACK
};

void dijkstra() {
    priority_queue<pair<int, int> >PQ;
    for (int i = 0; i < n; ++i) {
        color[i] = WHITE;
        d[i] = INFINITY;
    }
    d[0] = 0;
    PQ.push(make_pair(0,0));

    while (!PQ.empty()) {
        pair<int, int> p = PQ.top();
        PQ.pop();
        int target = p.second;

        color[target] = BLACK;
        if (d[target] < p.first * -1) continue;

        for (int j = 0; j < adj[target].size(); ++j) {
            int v = adj[target][j].first;
            if (color[v] != BLACK) {
                if(adj[target][j].second + d[target] < d[v]) {
                    d[v] = d[target] + adj[target][j].second;
                    color[v] = GRAY;
                    PQ.push(make_pair(d[v] * -1, v));
                }
            }
        }
    }

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

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int id, k;
        scanf("%d %d", &id, &k);
        for (int j = 0; j < k; ++j) {
            int t, c;
            scanf("%d %d", &t, &c);
            adj[id].push_back(make_pair(t,c));
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
// #include <vector> 
#include <algorithm>
#include <queue>
#include <cstdio> 
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
int d[MAX],color[MAX];
int n;
vector<pair<int, int> > adj[MAX];

void dijkstra()
{
    priority_queue<pair<int, int> > PQ;
    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        color[i] = 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;
            } 
        } 
    } 

    return;
}


int main()
{
    //freopen("in3.txt","r",stdin);
    int u,k,v,c;
    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();
    for (int i = 0; i < n; i++)
    {
        cout<<i<<" "<<d[i]<<endl; 
    } 
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<utility>
#include<limits>
using namespace std;
typedef pair<int, int> Edge;
int main()
{
	int n; cin >> n;
	vector< vector< Edge > > lists;

	for (int i = 0; i < n; i++)
	{
		vector<Edge> list;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			Edge edge;
			cin >> edge.second >> edge.first;
			list.push_back(edge);
		}
		lists.push_back(list);
	}

	vector<int> costs(n, INT32_MAX);
	costs[0] = 0;
	priority_queue<Edge> queue;
	for (Edge edge : lists[0])
		queue.push(edge);

	while (!queue.empty())
	{
		Edge edge = queue.top(); queue.pop();
		int dest = edge.second;
		int cost = edge.first;
		if (costs[dest] < cost)continue;
		int new_cost = costs[edge.second] = edge.first;

		for (Edge next : lists[dest])
		{
			next.first += new_cost;
			if(costs[next.second]== INT32_MAX)
				queue.push(next);
		}
	}
	for (int i = 0; i < n; i++)
		cout << i << " " << costs[i] << endl;

	char c;
	cin >> c;

	return 0;
}