Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

C++: #include<bits/stdc++.h>
using namespace std;
const int maxn = 1111;
#define INF 0x3f3f3f
int n;
struct qnode				//dis
{
	int v, c;
	qnode(int _v=0,int _c=0):v(_v),c(_c){}
	bool operator < (const qnode &r)const
	{
		return c > r.c;
	}
};
struct Edge
{
	int v,cost;
	Edge(int _v=0,int _cost =0):v(_v),cost(_cost){}
};
vector<Edge> E[maxn];
bool vis[maxn];
int dis[maxn];
void Dijkstra(int n, int s)
{
	memset(vis, false, sizeof(vis));
	fill(dis, dis + n, INF);
	priority_queue<qnode> que;			//存dis
	dis[s] = 0;
	que.push(qnode(s, 0));
	qnode temp;
	while (que.size())
	{
		temp = que.top();
		que.pop();
		int u = temp.v;
		if (vis[u])
			continue;
		vis[u] = true;
		for (int i = 0;i < E[u].size();i++)
		{
			int v = E[u][i].v;
			int cost = E[u][i].cost;
			if (!vis[v] && cost + dis[u] < dis[v])
			{
				dis[v] = dis[u] + cost;
				que.push(qnode(v, dis[v]));
			}
		}
	}
}
void addedge(int u, int v, int w)
{
	E[u].push_back(Edge(v, w));
}
int main()
{
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		int a, b, w,k;
		cin >> a >> k;
		for (int j = 0;j < k;j++)
		{
			cin >> b >> w;
			addedge(a, b, w);
		}
	}
	Dijkstra(n,0);
	for (int i = 0;i < n;i++)
	{
		cout<<i<<" "<< dis[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

constexpr int INF = (1 << 30) - 1;
int n;
int dist[105][105];
int d[105];
bool used[105] = {};

void Dijkstra()
{

        fill_n(d, 105, INF);

        d[0] = 0;
        while ( true ) {
                int u = -1;
                for ( int i = 0; i < n; i++ ) {
                        if ( !used[i] && (u == -1 || d[u] > d[i]) ) {
                                u = i;
                        }
                }
                if ( u == -1 ) break;
                used[u] = true;
                for ( int i = 0; i < n; i++ ) {
                        d[i] = min(d[i], d[u] + dist[u][i]);
                }
        }
}

int main()
{
        fill_n(*dist, 105 * 105, INF);
        cin >> n;
        for ( int i = 0; i < n; i++ ) {
                int u, k;
                cin >> u >> k;
                for ( int j = 0; j < k; j++ ) {
                        int v, c;
                        cin >> v >> c;
                        dist[u][v] = min(dist[u][v], c);
                }
        }
        Dijkstra();
        for ( int i = 0; i < n; i++ ) {
                cout << i << " " << d[i] << endl;
        }

        return (0);
}

C++: #include <iostream>
#include <queue>
#include <utility>
#include <vector>

struct Edge {
  int from, to, weight;
  Edge(int from, int to, int weight) : from(from), to(to), weight(weight) {}
};

struct Node {
  std::vector<Edge> ongoingEdges;
  void addEdge(Edge edge) {
    ongoingEdges.push_back(edge);
  }
};

class Graph {
private:
  std::vector<Node> nodes;
  int size;
public:
  Graph(int size): size(size) {
    nodes.resize(size);
  }
  void addEdge(Edge edge) {
    nodes[edge.from].addEdge(edge);
  }

  std::vector<int> calculateDist(int source) {
    std::vector<int> dist(size, (1 << 30));
    std::priority_queue< std::pair<int, int>, std::vector< std::pair<int, int> >, std::greater< std::pair<int, int> > > pq;

    pq.push(std::make_pair(0, source));
    dist[source] = 0;

    while(!pq.empty()) {
      int from = pq.top().second;
      pq.pop();

      for(Edge edge: nodes[from].ongoingEdges) {
        if(dist[edge.to] > dist[from] + edge.weight) {
          dist[edge.to] = dist[from] + edge.weight;
          pq.push({dist[edge.to], edge.to});
        }
      }

    }

    return dist;
  }
};

int main() {
  int n;
  std::cin >> n;
  Graph graph(n);

  for(int i = 0; i < n; i++) {
    int u, k;
    std::cin >> u >> k;

    for(int i = 0; i < k; i++) {
      int v, c;
      std::cin >> v >> c;
      graph.addEdge(Edge(u, v, c));
    }

  }

  std::vector<int> dist = graph.calculateDist(0);

  for(int i = 0; i < n; i++) {
    std::cout << i + 1 << ' ' << dist[i] << std::endl;
  }

}

C++: #include<iostream>
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF 1000000
#define BLACK 2
#define GRAY 1
#define WHITE 0
using namespace std;

int Node[100][100];
int Cost[100];

void dijkstra()
{
	int Color[100];
	REP(i, 100)Color[i] = WHITE;
	REP(i, 100)Cost[i] = INF;

	Color[0] = GRAY;
	Cost[0] = 0;

	while (true)
	{
		int min_index = -1;
		int min_value = INF;
		REP(i, 100)
		{
			if (Color[i] != BLACK && min_value>Cost[i])
			{
				min_value = Cost[i];
				min_index = i;
			}
		}
		if (min_index == -1)break;

		REP(i, 100)
		{
			if (Color[i] != BLACK && i != min_index && Node[min_index][i]!=INF && Node[min_index][i]+min_value<Cost[i])
			{
				Cost[i] = min_value+Node[min_index][i];
				Color[i] = GRAY;
			}
		}
		Color[min_index] = BLACK;
	}
}

int main()
{
	REP(i,100)
	{
		REP(j, 100)
		{
			Node[i][j] = INF;
		}
	}
	REP(i, 100)Node[i][i] = 0;
	int n;
	cin >> n;
	REP(i,n)
	{
		int u, k;
		cin >> u >> k;
		REP(j,k)
		{
			int v, c;
			cin >> v >> c;
			Node[u][v] = c;
		}
	}
	dijkstra();
	REP(i, n)
	{
		cout << i << " " << Cost[i] << endl;
	}

	return 0;
}