Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include<iostream>
using namespace std;

static const int MAX =100;
static const int INFTY = (1<<21);
static const int black= 2;
static const int gray= 1;
static const int white= 0;

int n,M[MAX][MAX];

void d()
{
  int i,u,j,minv;
  int d[MAX],iro[MAX];

  for(i=0;i<n;i++)
    {
      d[i] = INFTY;
      iro[i] = white;
    }

  d[0] = 0;
  iro[0] = gray;
  while(1)
    {
      minv = INFTY;
      u = -1;
      for(i=0;i<n;i++)
	{
	  if(minv > d[i] && iro[i] != black)
	    {
	      u = i;
	      minv = d[i];
	    }
	}
      if(u==-1) break;
      iro[u] = black;
      for(j=0;j<n;j++)
	{
	  if(iro[j] != black && M[u][j] != INFTY)
	    {
	      if( d[j] > d[u] + M[u][j])
		{
		  d[j] = d[u] + M[u][j];
		  iro[j] = gray;
		}
	    }
	}
    }

  for(int i =0;i < n;i++)
    {
      cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}

int main()
{
  cin >> n;
  for( int i = 0; i < n; i++)
    {
      for(int p = 0; p < n; p++)
	{
	  M[i][p] = INFTY;
	}
    }

  int k,c,u,v;
  for(int i =0 ; i < n ; i++)
    {
      cin >> u >> k;
      for(int p = 0; p < k; p++)
	{
	  cin >> v >> c;
	  M[u][v] = c;
	}
    }
  d();

  return 0;
}

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;
//}