Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int M=10000;
static const int INF=(1<<20);
int n;
vector<pair<int,int > > a[M];
void dijkstra(){
	priority_queue<pair<int,int> > Q;
	int col[M];
	int d[M];
	for(int i=0;i<n;i++){
		col[i]=0;
		d[i]=INF;
	}
	d[0]=0;col[0]=1;
	Q.push(make_pair(0,0));
	while(!Q.empty()){
		pair<int,int>f=Q.top();Q.pop();
		int u=f.second;col[u]=2;
		if(d[u]<f.first*(-1))continue;
		for(int j=0;j<a[u].size();j++){
			int v=a[u][j].first;
			if(col[v]==2)continue;
			if(d[v]>d[u]+a[u][j].second){
				d[u]=d[u]+a[u][j].second;
				Q.push(make_pair(d[v]*(-1),v));
				col[v]=1;
			}
		}
	}
	for(int i=0;i<n;i++)cout<<i<<' '<<(d[i]==INF?-1:d[i])<<endl;
}
int main() {
	int k,u,v,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v>>c;
			a[u].push_back(make_pair(v,c));
		}
	}
	dijkstra();
}

C++: #include <bits/stdc++.h>
#define MAX_E 1000000
#define MAX_V 100000
#define INF 1e9
typedef long long ll;
using namespace std;
/*??????????????????????????? O(V*E)*/

//??????from????????????to???????????????cost??????
struct edge{int from, to, cost;};
edge es[MAX_E]; //???
ll d[MAX_V];   //???????????¢
int V,E;        //V???????????°???E????????°

//s???????????????????????????????????????????????¢????±???????.
void Bellman_Ford(int s){
  for(int i=0; i<V ;i++) d[i]=INF;
  d[s]=0;
  while(true){
    bool update=false;
    for(int i=0; i<E ;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to]> d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

//true??????????????????????????¨??????
bool find_negative_loop(){
  memset(d,0,sizeof(d));

  for(int i=0; i<V ;i++){
    for(int j=0; j<E ;j++){
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	
	//n??????????????´??°???????????????????????????????????¨?????????
	if(i == V-1) return true;
      }
    }
  }
  return false;
}

int main(){
  cin>>V;
  for(int i=0;i<V;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0,v,c;j<k;j++){
      cin>>v>>c;
      es[E++]=(edge){u,v,c};
    }
  }
  Bellman_Ford(0);
  for(int i=0;i<V;i++)
    cout<<i<<' '<<d[i]<<endl;
  /*  for(int i=0;i<V;i++){
    Bellman_Ford(i);
    cout <<i<<" "<<d[0]<<endl;
  }*/
}

C++: #include<stdio.h>
#include<string.h>
int n, dis[105], a[105][105];
bool vst[105];
void dijkstra()
{
    memset(vst, 0, sizeof(vst));
    memset(dis, 0x3f3f3f3f, sizeof(dis));
    dis[0] = 0;
    for(int i = 0; i < n; i++)
    {
        int k = n;
        for(int j = 0; j < n; j++)
            if(!vst[j] && dis[k] > dis[j]) k = j;
        vst[k] = 1;
        for(int j = 0; j < n; j++)
            if(!vst[j] && dis[j] > dis[k] + a[k][j])
                dis[j] = dis[k] + a[k][j];
    }
}
int main()
{
    scanf("%d", &n);
    memset(a, 0x3f3f3f3f, sizeof(a));
    for(int i = 1; i <= n; i++)
    {
        int m, j;
        scanf("%d%d", &m, &j);
        while(j--){
            int k, t;
            scanf("%d%d", &k, &t);
            if(t < a[m][k]) a[m][k] = t;
        }
    }
    dijkstra();
    for(int i = 0; i < n; i++)
        printf("%d %d\n", i, dis[i]);
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int u,k,v,c;
	int i,j;
	int MAX=INT_MAX;
	int box[101][101];
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i==j)	box[i][j]=0;
			else		box[i][j]=MAX;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v>>c;
			box[u][v]=c;
		}
	}
	// for(i=0;i<n;i++){
		// for(j=0;j<n;j++){
			// if(box[i][j]==MAX)	cout<<"★"<<" ";
			// else				cout<<box[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(box[i][k]!=MAX&&box[k][j]!=MAX){
					box[i][j]=min(box[i][j],box[i][k]+box[k][j]);
				}
			}
		}
	}
	// for(i=0;i<n;i++){
		// for(j=0;j<n;j++){
			// if(box[i][j]==MAX)	cout<<"★"<<" ";
			// else				cout<<box[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	for(i=0;i<n;i++){
		cout<<i<<" "<<box[0][i]<<endl;
	}
	return 0;
}

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

#define N_MAX 100

int M[N_MAX][N_MAX];
int d[N_MAX];
bool is_belong_to_sssp[N_MAX];

int main(){

  int n;
  scanf("%d", &n);

  //initialize
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      M[i][j] = INT_MAX;
    }
  }

  // read weigts
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    for(int j=0; j<k; j++){
      int v,c;
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  // initialize cost
  d[0] = 0;
  is_belong_to_sssp[0] = false;
  for(int i=1; i<n; i++){
    d[i] = INT_MAX;
    is_belong_to_sssp[i] = false;
  }

  //dijkstra's algorithm
  for(int i=0; i<n; i++){
    // select node u in V-S that has minimum cost
    int min_cost = INT_MAX;
    int u = 1;
    for(int j=0; j<n; j++){
      if(!is_belong_to_sssp[j] && d[j] < min_cost){
        u = j;
        min_cost = d[j];
      }
    }

    // add u to is_belong_to_sssp
    is_belong_to_sssp[u] = true;

    // update node in V-S and adjacent to u
    for(int v=0; v<n; v++){
      if(!is_belong_to_sssp[v] && M[u][v] != INT_MAX){
        if(d[u] + M[u][v] < d[v]){
          d[v] = d[u] + M[u][v];
        }
      }
    }
  }

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

  return 0;
}

C++: #include <queue>
#include <cstdio>
#include <vector>
using namespace std;
int V, E, s, t, p, q, d[100]; vector<int> G[100];
int main() {
	scanf("%d%d", &V, &E);
	for(int i = 0; i < V; i++) {
		scanf("%d%d", &s, &t);
		for(int j = 0; j < t; j++) {
			scanf("%d%d", &p, &q);
			G[i].push_back(make_pair(p, q));
		}
	}
	for(int i = 1; i < V; i++) d[i] = 999999999;
	priority_queue<pair<int, int> > que; que.push(make_pair(0, 0));
	while(!que.empty()) {
		int v = que.top().second; que.pop();
		for(int i = 0; i < G[v].size(); i++) {
			int u = G[v][i].first, w = G[v][i].second;
			if(d[u] > d[v] + w) {
				d[u] = d[v] + w;
				que.push(make_pair(-d[u], u));
			}
		}
	}
	for(int i = 0; i < V; i++) printf("%d %d\n", i, d[i]);
	return 0;
}