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()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	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 _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_N =10000;
int V;
int cost[MAX_N][MAX_N];
int d[MAX_N];
bool visit[MAX_N];
void dijkstra(int s){
	d[s]=0;
	while(true){
		int v =-1;
		for(int u = 0;u < V;u++){
			if(!visit[u]&&(v==-1||d[u] < d[v])){
				v = u;
			}
		}
		if(v==-1)break;
		visit[v]=true;
		for(int u = 0;u < V;u++){
			d[u] =min(d[u],d[v]+cost[v][u]);
		}
	}
}

int main(){
	cin>>V;
	for(int i =0;i <V;i++){
		d[i]=INF;
		visit[i]=false;
		for(int j =0;j <V;j++){
			cost[i][j]=INF;

		}
	}
	for(int i =0;i < V;i++){
		int u,k;
		cin>>u>>k;
		for(int j =0;j <k;j++){
			int v,c;
			cin>>v>>c;
			cost[u][v]=c;
		}
	}
	dijkstra(0);
	for(int i =0;i <V;i++){
		cout <<i<<" "<<d[i]<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

struct edge {
    ll to;
    ll cost;
};

int N;
vector<vector<edge>> G;
vector<ll> d(150);

void dijkstra() {
    priority_queue<pll, vector<pll>, greater<pll>> que;
    que.push({0, 0});
    d.assign(N, INF);
    d[0] = 0;
    while (!que.empty()) {
        pll p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;

        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    G.resize(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        rep(j, b) {
            ll c, d;
            cin >> c >> d;
            G[a].push_back({c, d});
        }
    }

    dijkstra();
    rep(i, N) { cout << i << " " << d[i] << endl; }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<20)
#define white 0
#define gray 1
#define black 2

int n;
vector<pair<int,int> > W[10000]; 
int color[10000],d[10000],p[100];

void dijkstra(int s) {
  d[s] = 0;
  priority_queue<pair<int,int> > PQ;
  PQ.push(make_pair(0,s));

  while(!PQ.empty()) {
    pair<int,int> f = PQ.top();PQ.pop();
    int u = f.second;
    color[u] = black;

    if(d[u] < f.first * (-1)) continue;

    for(int i = 0;i < W[u].size();i++) {
      int v = W[u][i].first;
      if(color[v] == black) continue;
      if(d[v] > d[u] + W[u][i].second) {
        d[v] = d[u] + W[u][i].second;
        PQ.push(make_pair(d[v] * (-1),v));
      }
    }
  }

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

int main() {

  cin >> n;
  

  for(int i = 0;i < n;i++) {
    int u,k;
    cin >> u >> k;
    color[i] = white;
    d[i] = INF;
    for(int j = 0;j < k;j++) {
      int v,c;
      cin >> v >> c;
      W[u].push_back(make_pair(v,c));
    }
  }

  dijkstra(0);

}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<20
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
int D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }
 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    D[V][u] = C;
      }    
  }
   
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++){
    printf("%d %d\n",i,D[0][i]);
  }
 
  return 0;
}

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

int INF = 1000000001;

typedef struct edge{
  int to;
  int cost;
} edge;

int N,E;
vector< edge > G[100000];
int mincost[100000];

void dijkstra(){
  /*
  priority_queue< pair<int,int>,
                  vector< pair<int,int> > ,
                  greater< pair<int,int> > > Q;
  */
  
  //priority_queue?????£?¨?
  typedef pair<int,int> P;
  priority_queue< P , vector<P> , greater<P> > Q;

  //mincost?????????????????????????????????
  for(int i=0;i<N;i++){
    mincost[i]=INF;
  }
  mincost[0]=0; //??????????????°????????????0

  Q.push( P(0,0) );

  //????????????dijkstra ?????¬???
  while(!Q.empty()){
    int pos=Q.top().second;// position
    int pos_cost=Q.top().first;
    Q.pop();
    
    //aoj0099????????????????????§???2 ??¨??????????????§????°?????????????????????????
    if( mincost[pos] < pos_cost )continue;
    
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(mincost[e.to] > pos_cost+e.cost){
        mincost[e.to]=pos_cost+e.cost;
        Q.push( P( mincost[e.to] , e.to ) );
      }
    }
  }

  for(int i=0;i<N;i++){
    cout<<i<<' '<<mincost[i]<<endl;
  }
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    int id,k;
    cin>>id>>k;
    for(int j=0;j<k;j++){
      edge e;
      cin>>e.to>>e.cost;
      G[id].push_back(e);
    }
  }

  dijkstra();
  
  return 0;
}