Go: package main

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

const (
	MAX_N      = 100
	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{1}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd()-1, v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 1
	} 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-1]
}

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-1] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode-1]
	edges := []Edge{}
	for i, v := range adjacents {
		if v > 0 {
			edges = append(edges, Edge{start: currentNode, end: i + 1, weight: v})
		}
	}
	return edges
}

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

C++: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>

struct Node {
	int id;
	std::vector<int> edge_to;
	std::vector<int> edge_cost;
	bool done;
	int cost;
};

int min(int x, int y)
{
	return x>y ? y : x;
}

void insert(Node* nodes, std::vector<int>& q, int t)
{
	std::vector<int>::iterator it = q.begin();
	for (; it != q.end(); ++it) {
		if (nodes[*it].id == nodes[t].id) return;
		if (nodes[*it].cost > nodes[t].cost) break;
	}
	q.insert(it, t);
}

int main()
{
	int n; std::cin >> n;
	
	Node* nodes = new Node[n];
	
	for (int i=0; i<n; i++) {
		nodes[i].done = false;
		nodes[i].cost = INT_MAX;
	}
	
	for (int i=0; i<n; i++) {
		int id, deg;
		std::cin >> id >> deg;
		nodes[i].id = id;
		for (int j=0; j<deg; j++) {
			int t, cost;
			std::cin >> t >> cost;
			nodes[i].edge_to.push_back(t);
			nodes[i].edge_cost.push_back(cost);
		}
	}
	
	std::vector<int> que;
	que.push_back(0);
	nodes[0].cost = 0;
	
	while (!que.empty()) {
		int s = que[0]; que.erase(que.begin());
		nodes[s].done = true;
		for (int k=0; k<nodes[s].edge_to.size(); k++) {
			int t = nodes[s].edge_to[k];
			int cost = nodes[s].edge_cost[k];
			if (nodes[t].done) continue;
			nodes[t].cost = min(nodes[t].cost, nodes[s].cost + cost);
			insert(nodes, que, t);
		}
	}
	
	for (int i=0; i<n; i++) {
		std::cout << nodes[i].id << " " << nodes[i].cost << std::endl;
	}
	
	delete[] nodes;
	
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

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

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(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 j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

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

    // adj = new vector<pair<int, int>>[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);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 1<<30
struct edge{int to,cost;};
vector<edge> G[101];
int d[101];
bool visited[101];
void dijkstra(int n){
  fill(d+1,d+101,INF);
  memset(visited,false,sizeof(visited));
  for(int i=0;i<n;++i){
    int id=-1;
    for(int j=0;j<n;++j){
      if(!visited[j]){
        if(id==-1||d[id]>d[j]) id=j;
      }
    }
    visited[id]=true;
    for(int j=0;j<G[id].size();++j){
      edge e=G[id][j];
      d[e.to]=min(d[e.to],d[id]+e.cost);
    }
  }
}
int main(){
  int n; cin>>n;
  for(int i=0;i<n;++i){
    int u,k; cin>>u>>k;
    for(int j=0;j<101;++j) G[i].clear();
    for(int j=0;j<k;++j){
      int c,v; cin>>c>>v;
      edge e; e.to=c, e.cost=v;
      G[u].push_back(e);
    }
    dijkstra(n);
  }
  for(int i=0;i<n;++i) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include<iostream>
using namespace std;
#define MAX 100+5
#define white 0
#define black 1
#define INF 100000*100+5
int m[MAX][MAX],color[MAX],d[MAX],num;
void dijkstra(){
	d[0]=0;int now_node;
while(true){
	int minc=INF;
	for(int i=0;i<num;i++){
		if(!color[i]&&d[i]<minc){
			minc=d[i];now_node=i;
		}
	}
     	if(minc==INF) break;
		color[now_node]=black;
		for(int i=0;i<num;i++){
			if(color[i]==white&&m[now_node][i]+d[now_node]<d[i]){
				d[i]=d[now_node]+m[now_node][i];
			}
		}
	
}
return ;
}
int main(){
	cin>>num;
	for(int i=0;i<num;i++){
		for(int j=0;j<num;j++){
			m[i][j]=INF;
		}
	}
	int row,n,col,val;
	for(int i=0;i<num;i++){
		cin>>row;
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>col>>val;
			m[row][col]=val;
		}
	}
	for(int i=0;i<num;i++){
		d[i]=INF;color[i]=0;
	}
	dijkstra();
	for(int i=0;i<num;i++){
		cout<<i<<" "<<d[i]<<endl;
	}
}