Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

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;
}