Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			A[i][j] = T
		}
	}
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			A[u][v] = c
		}
	}
	Shortestsearch()
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF INT_MAX/3
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define MAX_N 10000
int G[MAX_N][MAX_N];
int MIN_COSTS[MAX_N];

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    REP(j, n) {
      G[i][j] = INT_MAX;
    }
    MIN_COSTS[i] = INT_MAX;
  }
  int u, k;
  int v, c;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v >> c;
      G[u][v] = c;
    }
  }

  priority_queue<P> q;
  int position;
  int new_cost;
  q.push(P(0, 0));
  while (q.size() != 0){
    position = q.top().first;
    MIN_COSTS[position] = q.top().second;
    q.pop();
    REP(i, n) {
      if (G[position][i] != INT_MAX) {
        new_cost = MIN_COSTS[position] + G[position][i];
        if (new_cost < MIN_COSTS[i]) {
          MIN_COSTS[i] = new_cost;
          q.push(P(i, new_cost));
        }
      }
    }
  }

  REP(i, n) {
    cout << i << ' ' << MIN_COSTS[i] << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef pair< int, int > Pi;
const int INF = 1 << 30;
struct edge: vector< Pi > {
  void add_edge(int to, int cost){
    push_back(Pi(to,cost));
  }
} info[100000];
int hoge[100000];

void bfs(const int& st, const int& V){
  fill_n( hoge, V, INF);
  queue< int > que;
  que.push(st);
  hoge[st] = 0;
  while(!que.empty()){
    int p = que.front();
    que.pop();
    for(int i = 0 ; i < info[p].size() ; i++){
      int cost = info[p][i].second;
      int to = info[p][i].first;
      if( cost + hoge[p] < hoge[to]){
        que.push(to);
        hoge[to] = cost + hoge[p];
      }
    }
  }
}

int main(){
  int N;
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    while(k--){
      int v, c;
      scanf("%d %d", &v, &c);
      info[u].add_edge( v, c);
    }
  }
  bfs(0, N);
  for(int i = 0 ; i < N ; i++ ){
    printf("%d %d\n", i, hoge[i]);
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define D_MAX 1 << 21
#define N_MAX 100
using namespace std;

int dis[N_MAX];
int n;

struct node {
  int to;
  int cost;
  node(int to,int cost) {
    this->to = to;
    this->cost = cost;
  }
};

void dijkstra(int st,vector< vector<node*> > &nodes) {
  for(int i=0;i<n;i++) dis[i] = D_MAX;
  dis[st] = 0;
  bool visited[n]; for(int i=0;i<n;i++) visited[i] = false;
  vector<int> vertexes;
  visited[st] = true;
  vertexes.push_back(st);
  int pre_cost = 0;
  while(vertexes.size() < n) {
    // update distance list
    int v = vertexes[vertexes.size()-1];
    for(int j=0;j<nodes[v].size();j++) {
      int u = nodes[v][j]->to;
      if(visited[u]) continue;
      int cost = nodes[v][j]->cost + pre_cost;
      dis[u] = min(dis[u],cost);
    }
    // find vertex which has smallest distance.
    int next_v;
    int minimum = D_MAX;
    for(int i=0;i<n;i++) {
      if(visited[i]) continue;
      if(dis[i] < minimum) {
        minimum = dis[i];
        next_v = i;
      }
    }
    visited[next_v] = true;
    vertexes.push_back(next_v);
    pre_cost = dis[next_v];
  }
}

int main() {
  scanf("%d",&n);
  int u,k,v,c;
  vector<vector< node*> > nodes;
  nodes.resize(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);
      nodes[u].push_back(new node(v,c));
    }
  }

  // check
  /*
  for(int i=0;i<nodes.size();i++) {
    for(int j=0;j<nodes[i].size();j++) {
      printf("%2d :%2d %2d\n",i,nodes[i][j]->to,nodes[i][j]->cost);
    }
  }
  */

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

C++: #include <stdio.h>

using namespace std;


int main(){
	int n,count,t,min,min_index,tmp,left_node,right_node,dist;
	scanf("%d",&n);
	int distance[n][n],P[n];

	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++)distance[i][k]=100001;
		P[i]=0;
	}
	distance[0][0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		for(int k=0;k<tmp;k++){
			scanf("%d %d",&right_node,&dist);
			distance[left_node][right_node] = dist;
		}
	}

	while(count<n-1){

		min=100001;
		for(int i=1;i<n;i++){
			if(P[i]==0&&distance[0][i]<min){
				min_index = i;
				min = distance[0][i];
			}
		}
		t = min_index;
		P[t]=1;
		count++;

		for(int i=0;i<n;i++){
			if(distance[0][i] > distance[0][t]+distance[t][i]){
				distance[0][i]=distance[0][t]+distance[t][i];
			}
		}
	}

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1e9
using namespace std;
int M[100][100],d[100],p[100];
bool vist[100]={0};
void prim(int n){
	for(int i=0;i<n;i++) d[i] = INF;
	d[0] = 0;
	p[0] = -1;
	int mincost, u;
	while(1){
		mincost = INF;
		for(int i=0;i<n;i++)
			if(!vist[i] && d[i]<mincost)
				mincost = d[i], u = i;
		if(mincost == INF) break;
		vist[u] = 1;
		for(int i=0; i<n; i++)
			if(!vist[i] && M[u][i]!=-1 && d[u]+M[u][i]<d[i])
				d[i] = M[u][i] + d[u],
				p[i] = u;
	}
}
int main()
{	
	memset(M,-1,sizeof(M));
	int n,du,v,u; cin>>n;
	for(int i = 0;i < n;i++){
		scanf("%d%d",&v,&du);
		while(du--)
			scanf("%d",&u),
			scanf("%d",&M[v][u]);
	}
	prim(n);
	for(int i=0; i<n; i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}