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<iostream>
#include<cstdio>
#include<climits>
using namespace std;
 
#define N 1000000
int n;
 
int g[N][N];
 
int weight[N];
bool us[N];
 
//prim
void prim(){
 
  int v;
  
  weight[0]=0;
   
  while(true){
    v=-1;
    
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }
 
    if(v==-1)break;
    us[v]=true;
  
 
    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){
 
        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
  
}
 
 
int main(){
 
  int u,k1,c,v;
 
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=9953535;
    }
  }
 
  //load n
  cin >>n;
 
  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }
 
 
 
 
  //print
  prim();
 
  for(int i=0;i<n;i++){
    cout <<i<<" "<<weight[i]<<endl;
  }
  return 0;
 
}

C++: #include <iostream>
#include <functional>
#include <vector>

class link_vector{
	std::vector<int> vec;
	std::vector<int> &ind;
public:
	link_vector(std::vector<int> &ind): ind(ind) {}
	void print(){
		for(int i : vec){
			std::cout << i << " ";
		}
		std::cout << std::endl;
		for(int i : ind){
			std::cout << i << " ";
		}
		std::cout << std::endl;
	}
	void enlarge(){
		vec.push_back(int());
	}
	void reduce(){
		vec.pop_back();
	}
	void substitute(const int &i, const int &x){
		vec[i] = x;
		ind[x] = i;
	}
	int operator[](const int &i){
		return vec[i];
	}
	int size(){
		return vec.size();
	}
	int front(){
		return vec.front();
	}
	int back(){
		return vec.back();
	}
	bool empty(){
		return vec.empty();
	}
};

class heap{
	link_vector vec;
	std::function<bool(int, int)> fnc;
public:
	heap(std::vector<int> &ind, std::function<bool(int, int)> fnc): vec(ind), fnc(fnc) {}
	void push(int x){
		vec.enlarge();
		chmin(vec.size() - 1, x);
	}
	bool empty(){
		return vec.empty();
	}
	int top(){
		return vec.front();
	}
	void pop(){
		int x = vec.back();
		int i = 0;
		vec.reduce();
		for(;;){
			int j = i * 2 + 1;
			if(j + 1 < vec.size() && fnc(vec[j + 1], x) && fnc(vec[j + 1], vec[j])) ++j;
			else if(j >= vec.size() || fnc(x, vec[j])) break;
			vec.substitute(i, vec[j]);
			i = j;
		}
		vec.substitute(i, x);
	}
	void chmin(int i, int x){
		while(i != 0){
			int j = (i - 1) / 2;
			if(fnc(vec[j], x)) break;
			vec.substitute(i, vec[j]);
			i = j;
		}
		vec.substitute(i, x);
	}
	void print(){
		vec.print();
	}
};

struct edge{
	int to;
	int cost;
};

std::vector<int> dijkstra(std::vector<std::vector<edge>> e){
	std::vector<int> ret(e.size(), 0);
	std::vector<int> ind(e.size(), -1);
	std::vector<bool> fin(e.size(), false);

	heap h(ind, [&ret](int l, int r){ return ret[l] < ret[r]; });

	h.push(0);

	while(!h.empty()){
		int cur = h.top();
		h.pop();
		fin[cur] = true;
		for(edge i : e[cur]){
			if(!fin[i.to]){
				if(ind[i.to] == -1){
					ret[i.to] = ret[cur] + i.cost;
					h.push(i.to);
				}else if(ret[i.to] > ret[cur] + i.cost){
					ret[i.to] = ret[cur] + i.cost;
					h.chmin(ind[i.to], i.to);
				}
			}
		}
	}

	return ret;
}

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

	std::vector<std::vector<edge>> e(n);

	for(int i = 0; i < n - 1; ){
		std::cin >> i;
		int k;
		std::cin >> k;
		e[i].resize(k);
		for(int j = 0; j < k; ++j){
			std::cin >> e[i][j].to >> e[i][j].cost;
		}
	}

	std::vector<int> ans = dijkstra(e);

	for(int i = 0; i < n; ++i){
		std::cout << i << " " << ans[i] << std::endl;
	}
}

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

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

void dik()
{
  for (int i = 0; i < n; i++)
  {
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[0] = 0;
  color[0] = GRAY;
  int mincost;
  while (1)
  {
    mincost = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++)
    {
      if (color[i] != BLACK && d[i] < mincost)
      {
        mincost = d[i];
        u = i;
      }
    }
    if (u == -1)
      break;

    color[u] = BLACK;

    for (int v = 0; v < n; v++)
    {
      if (color[v] != BLACK && M[u][v] != INFTY)
      {
        if (M[u][v] + d[u] < d[v])
        {
          d[v] = M[u][v] + d[u];
          color[v] = GRAY;
        }
      }
    }
  }
}

int main()
{
  int v, k, s, t;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      M[i][j] = INFTY;
    }
  }

  for (int i = 0; i < n; i++)
  {
    scanf("%d %d", &v, &k);
    for (int j = 0; j < k; j++)
    {
      scanf("%d %d", &s, &t);
      M[v][s] = t;
      //M[s][v] = t;
    }
  }
  dik();

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

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAX 10000000

int b[110];

int solve(int a[110][110], int n){
	b[0] = 0;
	for(int i = 0;i < n;i++)
		for(int j = 1;j < n;j++)
			if(a[i][j] != -1)b[j] = min(b[j], a[i][j]+b[i]);
	return 0;
}

int main(){
	int a[110][110], n;
	fill((int*)a, (int*)(a+110), -1);
	fill(b, b+110, MAX);
	cin >> n;
	for(int i = 0;i < n;i++){
		int u, k, c, d;
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> c >> d;
			a[u][c] = d;
		}
	}
	
	
	
	for(int i = 0;i < n;i++)solve(a, n);
	for(int i = 0;i < n;i++){
		cout << i << " " << b[i] << endl;
	}
	
	return 0;
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/