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 <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vector<map<lli,lli> > graph;

lli n;
graph g;
lli u,k,v,c;
priority_queue<pll,vector<pll>,greater<pll> > q;
vbl vis;
vll ans;

int main(){
    cin >> n;
    g = graph(n);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v >> c;
            g[u][v] = c;
        }
    }
    vis = vbl(n);
    ans = vll(n);
    q.push(pll(0,0));
    while(!q.empty()){
        lli d = q.top().first;
        lli p = q.top().second;
        q.pop();
        if(vis[p]) continue;
        vis[p] = true;
        ans[p] = d;
        for(auto itr = g[p].begin();itr != g[p].end();itr++){
            if(!vis[itr->first]) q.push(pll(d+itr->second,itr->first));
        }
    }
    for(lli i = 0;i < n;i++) cout << i << " " << ans[i] << endl;
    return 0;
}

C++: #include <cstdio>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <functional>
using namespace std;

typedef pair<int,int> pii;

int main(){
	int n;
	scanf("%d", &n);
	vector<vector<pii> > G(n);
	for(int i = 0; i < n; ++i){
		int u, k, v, c;
		scanf("%d%d", &u, &k);
		for(int j = 0; j < k; ++j){
			scanf("%d%d", &v, &c);
			G[u].push_back(pii(c, v));
		}
	}

	vector<int> d(n, 1 << 30);
	d[0] = 0;
	priority_queue<pii,vector<pii>,greater<pii> > pq;
	pq.push(pii(0, 0));
	while(!pq.empty()){
		int c = pq.top().first;
		int u = pq.top().second;
		pq.pop();
		if(d[u] != c){ continue; }
		for(int i = 0; i < G[u].size(); ++i){
			int b = c + G[u][i].first;
			int v = G[u][i].second;
			if(d[v] > b){
				d[v] = b;
				pq.push(pii(b, v));
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		printf("%d %d\n", i, d[i]);
	}
}

C++: #include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
int main(){
	int a;
	int b;
	int s;
	int t;
	vector<int> n[100000];
	int nn[100000];
	vector<int> x[100000];
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >y;
	vector<pair<int, int> >::iterator yy;
	int z;
	int d[100000];
	int e;
	int c[100000];
	int zz;
	pair<int, int>pai;
	for (int i = 0; i < 100000; i++){
		d[i] = 1000000009;
		c[i] = 0;
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++){
		scanf("%d %d", &s, &b);
		for (int j = 0; j < b; j++){
			scanf("%d %d", &t, &e);
			n[s].push_back(t);
			nn[s]++;
			x[s].push_back(e);

		}
	}
	d[0] = 0;
	y.push(std::make_pair(d[0], 0));
	for (int i = 0; y.empty() == 0; i++){
		zz = 0;
		for (int j = 0; y.empty() == 0 && zz == 0; j++){
			pai = y.top();
			z = pai.second;
			if (c[z] == 0)zz++;
			else y.pop();
		}
		if (zz == 0)break;
		c[z] = 1;
		for (int j = 0; j < nn[z]; j++){
			if (d[z] + x[z][j] < d[n[z][j]])
			{
				d[n[z][j]] = d[z] + x[z][j];
				y.push(std::make_pair(d[n[z][j]], n[z][j]));
			}
		}
		y.pop();
	}
	for (int i = 0; i<a; i++)printf("%d %d\n",i,d[i]);
		return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int n;
vector<pair<int, int> > adj[10000];
string color[10000];
int d[10000];
const int INF = 1001001001;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > Q;

void dijkstra(int s){
    rep(i, n){
        color[i] = "WHITE";
        d[i] = INF;
    }
    d[s] = 0;

    Q.push(make_pair(0, s));

    while(!Q.empty()){
        pair<int, int> p = Q.top(); Q.pop();
        int u = p.second;
        color[u] = "BLACK";

        //if(d[u] < p.first) continue;

        for (int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i].second;
            if(color[v] != "BLACK"){
                if(d[u] + adj[u][i].first < d[v]){
                    d[v] = d[u] + adj[u][i].first;
                    color[v] = "GRAY";
                    Q.push(make_pair(d[v], v));
                }
            }
        }
    }
}

int main() {
    cin >> n;
    rep(i, n){
        int u; cin >> u;
        int k; cin >> k;
        rep(j, k){
            int v, c; cin >> v >> c;
            adj[i].push_back(make_pair(c, v));
        }
    }
    dijkstra(0);
    rep(i, n){
        cout << i << " " << d[i]  << endl;
    }

    return 0;
}

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

const int INF = 1 << 29;

struct Edge{
    int to, cost;
};
typedef pair<int, int> P;

int d[10001];

int main()
{
    int n,u,k,v,c;
    
    cin >> n;
    fill(d, d + n, INF);
    vector<Edge> G[10001];
    for(int i = 0; i < n; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; ++j){
            cin >> v >> c;
            Edge e = {v, c};
            G[u].push_back(e);
        }
    }
    
    priority_queue<P, vector<P>, greater<P>> que;
    d[0] = 0;
    que.push(P(0,0));
    
    while(!que.empty()){
        P 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(P(d[e.to], e.to));
            }
        }
    }
    
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << d[i] << endl;
    }
    
}

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

const long long MAX_N = 200000;
long long max_mdif, max_pdif, data, c, ans, s[MAX_N];
int main() {

	max_mdif = 0;
	max_pdif = 0;
	c = 0;
	cin >> data;

	for (int i = 0; i < data; ++i) {
		cin >> s[i];
	}

	for (int i = 1; i < data; ++i) {
		if (s[i] > s[i - 1]) {
			max_pdif += s[i] - s[i - 1];
			c++;
		}
	}
	if (c == 0) {
		for (int i = 1; i < data; ++i) {
			if (s[data - i] < s[data - i - 1]) {
				max_mdif = min(s[data - i] - s[data - i - 1], max_mdif);
			}
		}
	}
	if (c > 0) {
		ans = max_pdif;
	} else {
		ans = max_mdif;
	}

	cout << ans << endl;

	return 0;
}