Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

struct Edge{
    ll target;
    ll weight;
};

struct State{
    ll node;
    ll sum_of_weight;

    bool operator < (const State& s)  const {
        return sum_of_weight > s.sum_of_weight;
    }
};

typedef vector<vector<Edge> > graph;

void dijkstra(graph &g, vector<ll>&d, ll start){

    priority_queue<State> pq;
    pq.push(State{start,0});

    while( pq.size() ){

        State s = pq.top(); pq.pop();

        if( d[s.node] != -1 ) continue;
        d[s.node] = s.sum_of_weight;

        for(auto edge: g[s.node]) {
            if( d[edge.target] != -1 ) continue;
            pq.push(State{edge.target, s.sum_of_weight + edge.weight});

        }
    }

}


int main(){

    ll N;
    cin >> N;

    graph G(N);
    for (int i = 0; i < N; i++)
    {
        ll u,k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            ll v,c;
            cin >> v >> c;
            G[u].push_back(Edge{v,c});
        }
    }

    vector<ll> d(N,-1);

    ll count = 1;
    dijkstra(G,d,0);

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

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main() {
	int n, u, k, v, c, i, j, d[100][100], m[100][100], o, p[100] = { 0 }, e, q = 0;
	memset(m, 0x7f, sizeof(m));
	memset(d, 0x7f, sizeof(d));
	d[0][0] = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v >> c;
			m[u][v] = c;
		}
	}
	p[0] = 1;
	for (i = 1; i < n; i++) {
		o = d[0][n - 1];
		for (j = 0; j < n; j++) {
			d[i][j] = min(d[i][j], m[q][j] + d[i - 1][q]);
			d[i][j] = min(d[i][j], d[i - 1][j]);
			if (o >= d[i][j] && p[j] == 0) {
				e = j;
				o = d[i][j];
			}
		}
		p[e] = 1;
		q = e;
	}
	for (i = 0; i < n; i++)cout << i << ' ' << d[n - 1][i] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct node{
	int v,c;
	bool operator<(const node&p)const{
		return c>p.c;
	}
};
int d[100005];
vector<node> e[100005];
bool ok[100005];
int n;
void solve(){
	priority_queue<node> q;
	ok[0]=1;
	for(int i=0;i<e[0].size();i++)q.push(e[0][i]);
	int k=1;
	while(k!=n){
		node v=q.top();q.pop();
		if(ok[v.v])continue;
		d[v.v]=v.c;
		ok[v.v]=1;
		k++;
		for(int j=0;j<e[v.v].size();j++)
			q.push({e[v.v][j].v,e[v.v][j].c+v.c});
	}
	for(int i=0;i<n;i++)
		cout<<i<<' '<<d[i]<<"\n";
}
int main(){
//	freopen("a.txt","r",stdin);
	cin.tie(0);
	int u,v,k,c;
	cin>>n;
	while(cin>>u>>k){
		for(int i=0;i<k;i++){
			cin>>v>>c;
			e[u].push_back({v,c});
		}
	}
	solve();
	return 0;
}

C++: /*
 ********************************************************************************
 *  Author: ThoseBygones
 *  Version: V1.0
 *  Date: 2018-06-27
 *  Subject: ACM-ICPC
 *  Language: C/C++11
 *  OJ: AOJ
 *  Algorithm: 最短路Dijkstra
 ********************************************************************************
 *  Algo-Description:
 ********************************************************************************
 */

//#include <bits/stdc++.h>  //For CodeForces only

//#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x)
{
    return x * x;
}
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
#define forIt(mp,it) for(__typeof(mp.begin()) it = mp.begin();it!=mp.end();it++)
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0);

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lowbit(u) (u&(-u))
#define MAXN 105
#define MAXE (MAXN*MAXN)>>1

typedef int Type;

class Dijkstra
{
public:
    int head[MAXN],nxt[MAXE],cnt;
    Type d[MAXN];
    struct Edge
    {
        int v;
        Type cost;
        Edge() {}
        Edge(int v,Type cost):v(v),cost(cost) {}
        bool operator<(const Edge& ed) const
        {
            return cost>ed.cost;
        }
    } e[MAXE];
    bool vis[MAXN];

    //初始化，n为点数
    void init(int n)
    {
        cnt = 0;
        for(int i = 0; i<n; i++)
            head[i] = -1;
    }

    inline void addEdge(int u,int v,Type cost)
    {
        e[cnt] = Edge(v,cost);
        int tmp = head[u];
        head[u] = cnt;
        nxt[cnt++] = tmp;
    }

    Type dijkstra(int s,int t,int n)
    {
        for(int i = 0; i<n; i++)
            d[i] = INF,vis[i] = false;
        d[s] = 0;
        priority_queue<Edge> q;
        q.push(Edge(s,0));
        while(!q.empty())
        {
            Edge ed = q.top();
            q.pop();
            vis[ed.v] = true;
            if(ed.v==t) //如果未给出终点t，则完全可以不要跟t有关的语句
                return d[t];
            for(int i = head[ed.v]; ~i; i = nxt[i])
            {
                Edge ee = e[i];
                if(!vis[ee.v]&&d[ee.v]>d[ed.v]+ee.cost)
                {
                    d[ee.v] = d[ed.v]+ee.cost;
                    /*
                     *  最短路树
                    	p[ee.v] = MP(u,i);
                    */
                    q.push(Edge(ee.v,d[ee.v]));
                }
            }
        }
        return d[t];
    }

    void buildGraph(int n)
    {
        for(int i=0; i<n; i++)
        {
            int u,num;
            scanf("%d%d",&u,&num);
            while(num--)
            {
                int v,w;
                scanf("%d%d",&v,&w);
                addEdge(u,v,w);
            }
        }
    }
} dij;

int main()
{
    int n;
    scanf("%d",&n);
    dij.init(n);
    dij.buildGraph(n);
    for(int i=0; i<n; i++)
        printf("%d %d\n",i,dij.dijkstra(0,i,n));
    return 0;
}