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<bits/stdc++.h>
using namespace std;

typedef pair< int, int > Pi;
struct edge{
  int to, cost;
};
typedef vector< vector< edge > > Graph;

int Dijkstra(Graph& info, int s, int g,
             vector< int >& min_cost) {
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  min_cost.resize(info.size(), -1);
  que.push( Pi( 0, s));
  min_cost[s] = 0;
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(p.second == g) return p.first;
    if(p.first > min_cost[p.second]) continue;
    for(int i = 0; i < info[p.second].size(); i++){
      edge& e = info[p.second][i];
      if(min_cost[e.to] == -1 ||
         p.first + e.cost < min_cost[e.to]){
        min_cost[e.to] = p.first + e.cost;
        que.push( Pi( min_cost[e.to], e.to));
      }
    }
  }
  return -1;
}
int main(){
  int n;
  cin >> n;
  Graph graph(n);
  vector< int > min_cost;
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    for(int i = 0; i < k; i++){
      int c, v;
      cin >> v >> c;
      graph[u].push_back( (edge){ v, c});
    }
  }
  Dijkstra( graph, 0, n, min_cost);
  for(int i = 0; i < n; i++){
    cout << i << " " << min_cost[i] << endl;
  }
}

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

const int INF = numeric_limits<int>::max();

struct edge {
    int u, v, c;
};
struct Graph {
    vector<edge> es;
    vector<int> d;
    Graph(int n) {
        d.assign(n, INF);
    }
};

int main()
{
    int n;
    cin >> n;
    Graph 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.es.push_back({u, v, c});
        }
    }

    g.d[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (edge e : g.es) {
            if (g.d[e.u] != INF && g.d[e.v] > g.d[e.u] + e.c) {
                g.d[e.v] = g.d[e.u] + e.c;
            }
        }
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111];
int used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      e[i][j]=INF;
  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;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(d[i]==INF) continue;
      if(u<0||d[i]<d[u]) u=i;
    }
    if(u<0) break;
    used[u]=1;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[u]+e[u][i]);
    }
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<iostream>
#include <iomanip>
#include<string>
#include<math.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int m, n, i, j, k, a, b, d;
int dis[1010][1010],e[1010], r[1010];
void init()
{
	memset(dis, inf, sizeof(dis));
	for (i = 0; i < 1010; i++)
		dis[i][i] = 0;
}
void add(int a, int b, int c)
{
	dis[a][b] = min(dis[a][b], c);
}
void floyd()
{
	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (dis[i][j] > dis[i][k] + dis[k][j])
					dis[i][j] = dis[i][k] + dis[k][j];
}
int main()
{
	int x, t, u, v;;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &x, &t);
		for (j = 0; j < t; j++)
		{
			scanf("%d %d", &u, &v);
			add(i, u, v);
		}
	}
	floyd();
	for(i=0;i<n;i++)
		printf("%d %d\n",i, dis[0][i]);
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <functional>
using namespace std;
int cost[100][100];
const int INF = 10000000;
int dijkstra(int n,int s,int g){
	typedef pair<int,int> P;
	priority_queue<P,vector<P>,greater<P> > pq;
	P p,tp;
	for(int i = 0;i < n;++i){
		p.first = cost[s][i];
		p.second = i;
		if(i == s) p.first = 0;
		pq.push(p);
	}
	while(!pq.empty()){
		p = pq.top();
		pq.pop();
		if(p.second == g) break;
		for(int i = 0;i < n;++i){
			if(cost[p.second][i] != INF){
				tp.first = p.first + cost[p.second][i];
				tp.second = i;
				pq.push(tp);
			}
		}
	}
	return p.first;
}
int main(){
	int n,m,a,b,c;
	cin >> n;
	for(int i = 0;i < 100;++i){
		for(int j = 0;j < 100;++j){
			cost[i][j] = INF;
		}
	}
	for(int i = 0;i < n;++i){
		cin >> a >> m;
		for(int j = 0;j < m;++j){
			cin >> b >> c;
			cost[a][b] = c;
		}
	}
	for(int i = 0;i < n;++i){
		cout << i << " " << dijkstra(n,0,i) << endl;
	}
	return 0;
}