Go: package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}

	d[0] = 0
	color[0] = GRAY
	for {

		minv = INFTY
		u := -1
		for i := 0; i < n; i++ {
			if minv > d[i] && color[i] != BLACK {
				u = i
				minv = d[i]
			}
		}
		if u == -1 {
			break
		}

		color[u] = BLACK

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

	}
	for i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			M[f][v] = c
		}
	}
	dijkstra()
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,n,k,m[150][150];
  for(int i=0;i<150;i++)for(int j=0;j<150;j++)m[i][j]=100001;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>k;
    for(int j=0;j<k;j++){
      cin>>a;
      cin>>m[i][a];
    }
  }
  int dist[100]={};
  int visited[100]={};
  for(int i=1;i<100;i++)dist[i]=100001;
  while(1){
    int i=-1;
    for(int j=0;j<n;j++){
      if(visited[j]==0){
	if(i==-1||dist[i]>dist[j]){
	  i=j;
	}
      }
    }
    if(i==-1)break;
    visited[i]=1;
    for(int j=0;j<n;j++){
      int A=dist[i]+m[i][j];
      if(dist[j]>A){
	dist[j]=A;
      }
    }
  }
  for(int i=0;i<n;i++)printf("%d %d\n",i,dist[i]);
  return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>
using namespace std;

static const int MAX_N = 100;

void dijkstra(vector<vector<pair<int, int> > > way)
{
    int d[way.size()];
    bool on[way.size()];
    for (int i = 0; i < way.size(); i++) {
        d[i] = INT_MAX;
        on[i] = false;
    }
    d[0] = 0;
    while (1) {
//        cout << "d:";
//        for (int i = 0; i < way.size(); i++) {
//            cout << " " << d[i];
//        }
//        cout << endl;
        int u, minv = INT_MAX;
        for (int i = 0; i < way.size(); i++) {
            if (minv > d[i] && !on[i]) {
                minv = d[i];
                u = i;
            }
        }
        if (minv == INT_MAX) break;
        on[u] = true;
        for (auto itr = way.at(u).begin(); itr != way.at(u).end(); ++itr) {
            if (!on[itr->first]) {
                d[itr->first] = min(d[itr->first], d[u] + itr->second);
            }
        }
    }
    for (int i = 0; i < way.size(); i++) {
        cout << i << " " << d[i] << endl;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > way(n);
    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            way.at(u).push_back(make_pair(v, c));
        }
    }
    dijkstra(way);
    return 0;
}

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

typedef long long ll;

struct Edge {
    ll t,w;
};

struct State {
    ll v;
    ll score;
    bool operator < (const State& tgt) const {
	return score > tgt.score;
    }
};

vector<ll> dijkstra(vector<vector<Edge>>& G, const int start) {
    const ll V = G.size();

    vector<ll>res(V,INT_MAX);
    priority_queue<State> q;
    q.push( State{0,0} );
    while( q.size() ) {
	State s = q.top(); q.pop();
	if( res[s.v] != INT_MAX ) continue;
	res[s.v] = s.score;
	for(auto& e : G[s.v]) {
	    if( res[e.t] != INT_MAX ) continue;
	    q.push( State{e.t, s.score + e.w} );
	}
    }
    return res;
}


int main () {

    ll V; cin >> V;
    vector<vector<Edge>> G(V);
    for(int i=0; i<V; i++) {
	ll u,k; cin >> u >> k;
	for(int j=0; j<k; j++) {
	    ll v,w; cin >> v >> w;
	    G[i].push_back( Edge{v,w} );
	}
    }
    vector<ll> res = dijkstra(G,0);
    for(auto& e : res) cout << e << endl;
    
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
#include <list>
using namespace std;

#define NODE_NUM 100

class Node
{
private:
	//int next_node_list[NODE_NUM];
	list<int> next_node_list;
	//int next_node_num;
	//int next_weight_list[NODE_NUM];
	list<int> next_weight_list;
public:
	Node();
	void AddNextNode(int id, int weight);
	void SetWeight(int weight);
	void DistributeWeight();
	int id;
	int weight_from_0;
	bool check;
};

Node::Node()
{
	//next_node_num = 0;
	weight_from_0 = -1;
	check = false;
}

Node *Node_list;

priority_queue<Node, vector<Node>, greater<Node> > que;
bool operator> (const Node &n1, const Node &n2){
	return n1.weight_from_0 > n2.weight_from_0;
};

void Node::AddNextNode(int id, int weight)
{
	//next_node_list[next_node_num] = id;
	next_node_list.push_back(id);
	//next_weight_list[next_node_num] = weight;
	next_weight_list.push_back(weight);
	//next_node_num++;
}

void Node::SetWeight(int weight)
{
	if (weight_from_0 == -1 || weight < weight_from_0) {
		weight_from_0 = weight;
	}
}

void Node::DistributeWeight()
{
	check = true;
	/*for (int i = 0; i < next_node_num; i++) {
		if (Node_list[next_node_list[i]].check == false) {
			Node_list[next_node_list[i]].SetWeight(weight_from_0 + next_weight_list[i]);
			que.push(Node_list[next_node_list[i]]);
		}
	}*/
	list<int>::iterator itr2 = next_weight_list.begin();
	for(list<int>::iterator itr = next_node_list.begin(); itr != next_node_list.end(); itr++){	
		if (Node_list[*itr].check == false) {
			Node_list[*itr].SetWeight(weight_from_0 + *itr2);
			que.push(Node_list[*itr]);
		}
		itr2++;
	}
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		Node_list[i].id = i;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			Node_list[i].AddNextNode(v, c);
		}
	}

	//weight from 0 ?
	Node_list[0].check = true;
	Node_list[0].weight_from_0 = 0;
	Node_list[0].DistributeWeight();
	while (!que.empty()) {
		int id = que.top().id;
		que.pop();
		Node_list[id].DistributeWeight();
	}

	//output
	for (int i = 0; i < n; i++) {
		cout << i << " " << Node_list[i].weight_from_0 << endl;
	}
	
	return 0;
}