Go: package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

	for i := 0;i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			adj[u][v] = c
		}
	}

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}

C++: #include <iostream>

using namespace std;

static const int N = 100;
static const int INF = 1000000;

struct Vertex {
    bool in_S;
    int min_cost;
    int parent;
};

class SSSP {
private:
    int matrix[N][N];
    Vertex vertex[N];
    int n;

public:
    SSSP()
    {
        cin >> n;

        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                matrix[i][j] = INF;

        int u;
        int k;
        int v;
        int c;
        for (int i = 0; i < n; i++)
        {
            cin >> u;
            cin >> k;
            for (int j = 0; j < k; j++)
            {
                cin >> v >> c;
                matrix[u][v] = c;
            }
        }
    }

    void dijkstra(int start)
    {
        for (int i = 0; i < n; i++)
        {
            vertex[i].in_S = false;
            vertex[i].min_cost = INF;
        }
        vertex[start].min_cost = 0;
        vertex[start].parent = -1;

        while (true)
        {
            int u = -1;
            int mincost = INF;
            for (int i = 0; i < n; i++)
            {
                if (!vertex[i].in_S && vertex[i].min_cost < mincost)
                {
                    mincost = vertex[i].min_cost;
                    u = i;
                }
            }

            if (mincost == INF)
                break;

            vertex[u].in_S = true;

            for (int v = 0; v < n; v++)
            {
                if (!vertex[v].in_S && matrix[u][v] != INF)
                {
                    if (vertex[u].min_cost + matrix[u][v] < vertex[v].min_cost)
                    {
                        vertex[v].min_cost = vertex[u].min_cost + matrix[u][v];
                        vertex[v].parent = u;
                    }
                }
            }
        }
    }

    void print()
    {
        for(int i = 0; i < n; i++)
            cout << i << " " << vertex[i].min_cost << endl;
    }
};

int main()
{
    SSSP mst;
    mst.dijkstra(0);
    mst.print();
}

C++: // https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_12_B
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

#define INFint 2e9+1

ll gcd(ll a, ll b) { return __gcd(a,b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main(){
// start
  struct edge {int to,cost;};
  int N;
  cin>>N;
  vector<vector<edge>> G(N,vector<edge>());
  for(int i(0);i<N;i++){
    int k,u;
    cin>>k>>u;
    for(int j(0);j<u;j++){
      int v,c;
      cin>>v>>c;
      G[k].push_back({v,c});
    }
  }
  vector<int> d(N);
  fill(d.begin(),d.end(),INFint);
  // first: cont, second: node number 
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
  int start = 0;
  d[start] = 0;
  q.push({0,start});

  while(!q.empty()){
    pair<int,int> p = q.top();q.pop();                                                  
    int v = p.second;
    //if (d[v] < p.first) continue;
    for (int i(0);i<int(G[v].size());i++){
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        q.push({d[e.to],e.to});
      }
    }
  }
// end
  for(int i(0);i<N;i++){
    cout << i <<" " << d[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define MAX_E 1000000
#define MAX_V 100000
#define INF 1e9
typedef long long ll;
using namespace std;
/*??????????????????????????? O(V*E)*/

//??????from????????????to???????????????cost??????
struct edge{int from, to, cost;};
edge es[MAX_E]; //???
ll d[MAX_V];   //???????????¢
int V,E;        //V???????????°???E????????°

//s???????????????????????????????????????????????¢????±???????.
void Bellman_Ford(int s){
  for(int i=0; i<V ;i++) d[i]=INF;
  d[s]=0;
  while(true){
    bool update=false;
    for(int i=0; i<E ;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to]> d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

//true??????????????????????????¨??????
bool find_negative_loop(){
  memset(d,0,sizeof(d));

  for(int i=0; i<V ;i++){
    for(int j=0; j<E ;j++){
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	
	//n??????????????´??°???????????????????????????????????¨?????????
	if(i == V-1) return true;
      }
    }
  }
  return false;
}

int main(){
  cin>>V;
  for(int i=0;i<V;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0,v,c;j<k;j++){
      cin>>v>>c;
      es[E++]=(edge){u,v,c};
    }
  }
  
  for(int i=0;i<V;i++){
    Bellman_Ford(i);
    cout <<i<<" "<<d[0]<<endl;
  }
}