Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

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

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

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

C++: #include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,int>p;

vector<p>g[103];
int d[103];
main()
{
  int n;
  int u, k, v, c;
  
  scanf("%d", &n);
  for (int i = 0; i < n ; ++i) {
    scanf("%d %d", &u, &k);
    for(int j = 0; j < k ; ++j) {
      scanf("%d %d", &c, &v);
      g[u].push_back(p(c,v));
    }
    d[i] = 1 << 21;
  }
  
  priority_queue< p, vector<p>, greater<p> >p_que;
  p_que.push(p(0,0));
  d[0] = 0;
  while ( !p_que.empty() ) {
    p now = p_que.top(); p_que.pop();
    int pos = now.F;
    int cost = now.S;
    for ( int i = 0; i < g[pos].size() ; ++i) {
      int ncost = cost + g[pos][i].S;
      if ( ncost < d[g[pos][i].F] ) {
	d[g[pos][i].F] = ncost;
	p_que.push(p(g[pos][i].F,ncost));
      }
    }
  }

  for ( int i = 0; i < n ; ++i) {
    printf("%d %d\n", i, d[i]);
  }

  return (0);
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

ll squareDis(P x, P y){
    return (x.fs - y.fs) * (x.fs - y.fs) + (x.sc - y.sc) * (x.sc - y.sc);
}

bool judgeAcute(P x, P y, P z){
    ll dis1 = squareDis(x, y);
    ll dis2 = squareDis(x, z);
    ll dis3 = squareDis(y, z);

    return dis1 + dis2 > dis3;

}

class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int get_num_vertices(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


/**
 *
 * @param s 始点
 * @param g グラフ
 * @return sから各頂点への距離
 */
vector<ll> dijkstra1(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    unsigned int n = g.get_num_vertices();
    vector<bool> used(n, false);
    vector<ll> d(n, INF);

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

        if(v == -1) break;

        used[v] = true;
        for(auto e: g[v]){
            d[e.vertice] = min(d[e.vertice], d[v] + e.weight);
        }
    }

    return d;
}


vector<ll> dijkstra2(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    typedef pair<ll, int> Ptmp;  // firstは最短距離、secondは頂点の番号

    unsigned int n = g.get_num_vertices();
    priority_queue<Ptmp, vector<Ptmp>, greater<Ptmp>> que;
    vector<ll> d(n, INF);

    d[s] = 0;
    que.push(Ptmp(d[s], s));

    while(!que.empty()){
        Ptmp p = que.top();   que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(auto e: g[v]){
            if(d[e.vertice] > d[v] + e.weight){
                d[e.vertice] = d[v] + e.weight;
                que.push(Ptmp(d[e.vertice], e.vertice));
            }
        }
    }

    return d;
}



int main(){
    uint 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.add_edge(u, v, c);
        }
    }

    vector<ll> res = dijkstra2(0, g);
    for(int i = 0; i < n; i++){
        cout << i << " " << res[i] << endl;
    }
}


//int main(){
//    int n, m;   cin >> n >> m;
//
//    vector<vector<edge>> g(100);
//    vector<P> cor(n);
//
//    for(int i = 0; i < n; i++){
//        int x, y;   cin >> x >> y;
//        cor[i] = P(x, y);
//    }
//    for(int i = 0; i < m; i++){
//        int a, b, c;    cin >> a >> b >> c;
//        a--; b--;
//        g[a].emplace_back(edge{c, b});
//        g[b].emplace_back(edge{c, a});
//    }
//
//    vector<vector<edge>> g2;
//    map<P, int> mp;
//    g2.emplace_back(vector<edge>(0));
//    int n2 = 0;
//    mp[P(0, 0)] = n2++;
//
//    for(int i = 0; i < n; i++){
//        for(auto v: g[i]){
//            g2.emplace_back(vector<edge>(0));
//            mp[P(i, v.v)] = n2++;
//        }
//    }
//
//    for(int i = 0; i < n; i++){
//        for(auto v: g[i]){
//            for(auto u: g[i]){
//                if(!judgeAcute(cor[i], cor[u.v], cor[v.v])){
//                    g2[mp[P(i, v.v)]].emplace_back(edge{u.w, mp[P(u.v, i)]});
//                }
//            }
//        }
//    }
//
//
//
//    return 0;
//}