Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;

const int INF = 1 << 29;

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

  vector<vector<P>> edge(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;
      edge[u].push_back(P(c, v));
    }
  }

  vector<int> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  dist[0] = 0;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();

    for (int i = 0; i < edge[p.second].size(); i++) {
      if (dist[edge[p.second][i].second] > p.first + edge[p.second][i].first) {
        dist[edge[p.second][i].second] = p.first + edge[p.second][i].first;
        que.push(
            P(p.first + edge[p.second][i].first, edge[p.second][i].second));
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << " " << dist[i] << "\n";
  }

  return 0;
}

C++: #include<stdio.h>
#define N 101

int main()
{
  int i,j,n,count=0,v,c,c1,v1;
  int G[N][N],col[N],d[N],pi[N],mincost,i2;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++)
      G[i][j] = -1;
  }

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d%d",&v,&c);
    for(j = 0; j < c; j++){
      scanf("%d%d",&v1,&c1);
      G[v][v1] = c1;
    }
  }

  for(i = 0; i < n; i++){
    col[i] = 0;
    pi[i] = -1;
    d[i] = 10000001;
  }

  d[0] = 0;

  while(1){
    mincost = 10000001;
    for(i = 0; i < n; i++){
      if(col[i] != 2 && d[i] < mincost){
        mincost = d[i];
        i2 = i;
      }
    }
    if(mincost == 10000001)break;

    col[i2] = 2;


    for(i = 0; i < n; i++){
      if(G[i2][i] != -1 && col[i] != 2 && (G[i2][i]+d[i2]) < d[i]){
        pi[i] = i2;
        d[i] = G[i2][i] + d[i2];
        col[i] = 1;
      }
    }
  }
  for(i = 0; i < n; i++)printf("%d %d\n",i,d[i]);
    return 0;
}

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]=1000000;
  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]=1000000;
  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 <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int INF = INT_MAX/2;

struct Edge{
  int to;
  int cost;
  Edge():to(0),cost(0){}
  Edge(int to, int cost):to(to),cost(cost){}
  bool operator<(const Edge& e)const{
    return cost < e.cost;
  }
};

void dijkstra(const int start, const vector< vector<Edge> >& G1, vector< vector<int> >& G2){
  for(int i = 0;  i < G2[start].size(); i++){
    G2[start][i] = INF;
  }

  G2[start][0] = 0;

  priority_queue< P > que; //cost, pos
  que.push(P(0, start));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int pos = p.second;
    int cost = p.first;
    if(G2[start][pos] < cost) continue;
    for(int i = 0; i < G1[pos].size(); i++){
      int to = G1[pos][i].to;
      if(G2[start][to] > G2[start][pos] + G1[pos][i].cost){
        G2[start][to] = G2[start][pos] + G1[pos][i].cost;
        que.push(P(G2[start][to], to));
      }
    }
  }
}

int main(void){
  int n;
  cin >> n;
  vector< vector< Edge > >G(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;
      G[u].push_back(Edge(v, c));
    }
  }
  vector< vector<int> > ans(1, vector<int>(n));
  dijkstra(0, G, ans);
  for(int i = 0; i < n; i++) cout << i << " " << ans[0][i] << endl;

  return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
const int INF = 1e5 + 5;
const int maxn = 105;
int u[maxn];
int cost[maxn][maxn];
int d[maxn];
bool used[maxn];
int V;
void dijkstra(int s) {
	fill(d, d + V, INF);
	fill(used, used + V, false);
	d[s] = 0;
	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++)
			d[u] = min(d[u], d[v] + cost[v][u]);
	}
}
int main() {
	scanf("%d", &V);
	for(int i = 0; i < V; i++) 
		for(int j = 0; j < V; j++)
			cost[i][j] = INF;
	for(int i = 0; i < V; i++) {
		int u1 ,k;
		scanf("%d%d", &u1, &k);
		u[i] = u1; 
		while(k--) {
			int v, c;
			scanf("%d%d", &v, &c);
			if(c < cost[u1][v]) {
				cost[u1][v] = c;
				cost[v][u1] = c;	
			}
		}
		
	}
	dijkstra(0);
	for(int i = 0; i < V; i++)
		printf("%d %d\n", u[i], d[u[i]]);
	return 0;
}