Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

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

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<ll, ll>


const ll INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//
//-----class-----//
class UnionFind{
    public:
        vector<ll> par; //parents
        vector<ll> siz; // sizes of set
        vector<ll> rank; // rank of each element 
    UnionFind(ll n): par(n), siz(n, 1LL), rank(n){
        LREP(i, 0, n) par[i] = i;
    }
    //initialization
    /*
    void init(ll n){
        par.assign(n);
        siz.assign(n, 1LL);
        rank.assign(n);
        LREP(i, 0, n) par[i] = i;
    }
    */

    // find the root of x
    ll find(ll x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    //Unite two set including x or y
    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }else{
            par[y] = x;
            siz[x] += siz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //Do x and y belong to the same set?
    bool issame(ll x, ll y){
        return find(x) == find(y);
    }

};

struct edge{ ll to, cost; };
ll n;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<edge> G[n];
    LREP(i, 0, n){
        ll u, k;
        cin >> u >> k;
        LREP(j, 0, k){
            edge e;
            cin >> e.to >> e.cost;
            G[u].push_back(e);
        }
    }
    ll d[n];
    LREP(i, 0, n) d[i] = INF;
    priority_queue<P, vector<P>, greater<P>> q;
    d[0] = 0;
    q.push(P(0, 0));
    while(!q.empty()){
        P p = q.top(); q.pop();
        ll v = p.second;
        if(d[v] < p.first) continue;
        LREP(i, 0, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                q.push(P(d[e.to], e.to));
            }
        }
    }
    LREP(v, 0, n){
        cout << v << ' ' << d[v] << '\n';
    }

}

C++: #include<vector>
#include<iostream>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int V;
int d[MAX_V];
int cost[MAX_V][MAX_V];
bool used[MAX_V];

void dijkstra(int s)
{
	while (true)
	{
		int v = -1;
		for (int u = 0; u < V; u++)
		{
			if (!used[u] && (v == -1 || d[u] < d[v]))
			{
				v = u;
			}
		}
		if (v == -1)
		{
			break;
		}
		used[v] = true;

		for (int u = 0; u < V; u++)
		{
			//if (cost[v][u] = INF)
			//{
			//	continue;
			//}
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}

}
int main()
{
	cin >> V;
	for (int i = 0; i < MAX_V; i++)
	{
		for (int j = 0; j < MAX_V; j++)
		{
			cost[i][j] = INF;
		}
	}
	for (int i = 0; i < MAX_V;i++)
	{
		d[i] = INF;
		used[i] = false;
	}
	for (int i = 0; i < V; i++)
	{
		int u;
		cin >> u;
		int k;
		cin >> k;
		for (int j = 0; j < k; i++)
		{
			int v_to;
			cin >> v_to;
			int c;
			cin >> c;

			cost[u][v_to] = c;

		}
	}

	dijkstra(0);

	for (int i = 0; i < V; i++)
	{
		cout << i << " " << d[i] << endl;
	}

	return 0;

}

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

class Dijkstra {
private:
  struct edge {
    int to, cost;
  };

  const int INF = 1e18;

  int V;
  vector<vector<edge>> G;
  vector<int> d;

  void add_edge(int from, int to, int cost) {
    G[from].push_back({to, cost});
  }

  void do_dijkstra(int s) {
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = p.second;
      if (d[v] < p.first)
        continue;
      for (int i = 0; i < G[v].size(); i++) {
        edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }
  }

public:
  Dijkstra(int V) : V(V), G(V, vector<edge>()), d(V) {}

  void addEdge(int from, int to, int cost) { return add_edge(from, to, cost); }
  void dijkstra(int s) { return do_dijkstra(s); }
  int get(int v) { return d[v]; }
};

signed main() {
  int N;
  cin >> N;

  Dijkstra dij(N);

  for (int i = 0; i < N; i++) {
    int u, k;
    cin >> u >> k;
    while (k--) {
      int v, c;
      cin >> v >> c;
      dij.addEdge(u, v, c);
    }
  }

  dij.dijkstra(0);

  for (int i = 0; i < N; i++) {
    cout << i << " " << dij.get(i) << endl;
  }
  return 0;
}