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 <cstdio>
#include <cctype>
#include <climits>
#include <vector>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true; else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	//return n; }
	return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

#define v vector
struct graph {
	struct node {int n, w;};
	v<v<node>> nodes;

	void read(int n) {
		nodes.resize(n);
		for (auto &x: nodes) {
			in();
			for (int k = in(); k--;) {
				int c = in();
				x.push_back({c, in()});
			}
		}
	}

	v<node> dks() {
		v<node> w(nodes.size(), {0, INT_MAX});
		w[0].w = 0;
		priority_queue<node> q;
		q.push({0, 0});
		while (!q.empty()) {
			node n = q.top();
			q.pop();
			for (node &x: nodes[n.n]) {
				w[x.n].w = min(w[x.n].w, n.w + x.w);
				if (!w[n.n].n)
					q.push({x.n, w[x.n].w});
			}
			w[n.n].n = 1;
		}
		return move(w);
	}
};

bool operator < (const graph::node &a, const graph::node &b) {
	return a.w > b.w;
}

int main() {
	graph g;
	g.read(in());
	int i = 0;
	for (auto &x: g.dks())
		out(i++, ' ', x.w, '\n');
}

C++: #include<iostream>
#include<vector>
#include<queue>
#define INF 1000000000

using namespace std;

struct vEdge {
	int adj;
	vector<int> weight;
	vector<int> tovtx;
	vEdge() {}

	void setadj(int a) { adj = a; }

	void setnum(int w, int n2) {
		weight.push_back(w); tovtx.push_back(n2);
	}
};

void dijkstra0(const vector<vEdge>& vedge, vector<int>& cost) {
	int mindex, min, temp, v,w, size = vedge.size(), count = 1;
	vector<bool> optimum(size, false);
	queue<int> qdata;
	cost.at(0) = 0; optimum.at(0) = true;

	while (count < size) {
		mindex = -1; min = INF;
		for (int i = 0; i < size; i++) if (optimum.at(i)) {
			for (int j = 0; j < vedge.at(i).adj;j++){
				v = vedge.at(i).tovtx.at(j);
				if (!optimum.at(v)) {
					w = vedge.at(i).weight.at(j);
					temp = cost.at(i) + w;
					if (temp < min) {
						min = temp;
						mindex = v;
					}
					if (temp < cost.at(v)) cost.at(v) = temp;
				}
			}
		}
		optimum.at(mindex) = true;
		count++;
	}

}

int main(void) {
	int size, num, adj, w, n2;
	cin >> size;

	vector<int> cost(size, INF);
	vector<vEdge> vedge(size);

	for (int i = 0; i < size; i++) {
		cin >> num >> adj;
		vedge.at(num).setadj(adj);
		for (int j = 0; j < adj; j++) {
			cin >> n2 >> w;
			vedge.at(num).setnum(w, n2);
		}
	}
	dijkstra0(vedge, cost);

	for (int i = 0; i < size; i++) cout << i << " " << cost.at(i) << endl;
	return 0;

}

C++: #include<bits/stdc++.h>
#define INF 0x3f3f3f3f 
using namespace std;
const int maxn = 11111;
int n, m;
struct edge
{
	int v, cost;
	edge(int _v=0,int _cost=0):v(_v),cost(_cost){}
};
vector<edge> g[maxn];
bool book[maxn];
int dis[maxn];
void myinit()
{
	memset(book, 0, sizeof(book));
	for (int i = 0; i < maxn; i++)
	{
		g[i].clear();
	}
	fill(dis, dis + maxn,INF);
}
void SPFA(int s)
{
	queue<int> q;
	q.push(s);
	book[s] = 1;//加入队列并标记 
	while (!q.empty())
	{
		int temp = q.front();
		q.pop();
		book[temp] = 0;//弹出队列并取消标记 
		for (int i = 0; i < g[temp].size(); i++)
		{
			if (g[temp][i].cost + dis[temp] < dis[g[temp][i].v])//比较 
			{
				dis[g[temp][i].v] = g[temp][i].cost + dis[temp];//更新路径 
				if (!book[g[temp][i].v])//若该点不在队列 
				{
					q.push(g[temp][i].v);
					book[g[temp][i].v] = 1;
				}
			}
		}
	}
}
void addedge(int u, int v, int w)
{
	g[u].push_back(edge(v, w));
}
int main()

{
	cin >> n;
	m = 0;
	myinit();
	for (int i = 0;i < n;i++)
	{
		int ve, en, co;
		int k;
		cin >> ve >> k;
		for (int j = 0;j < k;j++)
		{
			cin >> en >> co;
			addedge(ve, en, co);
		}
	}
	dis[0] = 0;
	SPFA(0);
	for (int i = 0;i < n;i++)
		cout << i << " " << dis[i] << endl;
	return 0;
}