AtCoder problem 013

C++ solution:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

const int inf = 2e9;

vector<int> bfs_with_cost(int n, vector<vector<pair<int, int>>> to, int start) {
  vector<int> dist(n + 1, inf);
  queue<int> q;
  dist[start] = 0;
  q.push(start);
  while (q.size() > 0) {
    int now = q.front();
    q.pop();
    for (auto next_pair : to[now]) {
      int next = next_pair.first;
      int cost = next_pair.second;
      if (dist[next] <= dist[now] + cost) {
        continue;
      }
      dist[next] = dist[now] + cost;
      q.push(next);
    }
  }
  return dist;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> to(n + 1, vector<pair<int, int>>(0));
  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    to[a].push_back({b, c});
    to[b].push_back({a, c});
  }
  vector<int> dist_start = bfs_with_cost(n, to, 1);
  vector<int> dist_end = bfs_with_cost(n, to, n);
  rep1(i, n) { cout << dist_start[i] + dist_end[i] << endl; }
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var m: int :: cui@inputInt()
	var graph: []list<Edge> :: #[n]list<Edge>
	for i(0, n - 1)
		do graph[i] :: #list<Edge>
	end for
	for i(0, m - 1)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		var c: int :: cui@inputInt()
		do graph[a].add((#Edge).init(b, c))
		do graph[b].add((#Edge).init(a, c))
	end for
	
	var dist1: []int :: dists(graph, 0)
	var distN: []int :: dists(graph, n - 1)
	
	for i(0, n - 1)
		var ans: int :: dist1[i] + distN[i]
		do cui@print("\{ans}\n")
	end for
	
	func dists(graph: []list<Edge>, start: int): []int
		var n: int :: ^graph
		var res: []int :: [lib@intMax].repeat(^graph)
		do res[start] :: 0
		var pq: PriorityQueue :: #PriorityQueue
		do pq.add(-(0 + start))
		while loop(pq.len <> 0)
			var data: int :: -pq.top()
			do pq.pop()
			var u: int :: data % n
			if(res[u] < data / n)
				skip loop
			end if
			
			do graph[u].head()
			for i(0, ^graph[u] - 1)
				var e: Edge :: graph[u].get()
				var v: int :: e.v
				var dist: int :: e.dist
				if(res[u] + dist < res[v])
					do res[v] :: res[u] + dist
					do pq.add(-(res[v] * n + v))
				end if
				do graph[u].next()
			end for
		end while
		ret res
		
		class PriorityQueue()
			var data: []int
			+var len: int
			*func ctor()
				do me.data :: #[1024]int
				do me.len :: 0
			end func
			+func add(elem: int)
				var n: int :: me.len
				if(^me.data = me.len)
					do me.data :~ #[me.len]int
				end if
				do me.data[me.len] :: elem
				do me.len :+ 1
				
				while(n <> 0)
					var i: int :: (n - 1) / 2
					if(me.data[n] > me.data[i])
						var tmp: int :: me.data[n]
						do me.data[n] :: me.data[i]
						do me.data[i] :: tmp
					end if
					do n :: i
				end while
			end func
			+func pop()
				var n: int :: me.len - 1
				do me.data[0] :: me.data[n]
				do me.len :- 1
				var i: int :: 0
				var j: int :: 1
				while(j < n)
					if(j <> n - 1 & me.data[j] < me.data[j + 1])
						do j :+ 1
					end if
					if(me.data[i] < me.data[j])
						var tmp: int :: me.data[j]
						do me.data[j] :: me.data[i]
						do me.data[i] :: tmp
					end if
					do i :: j
					do j :: 2 * i + 1
				end while
			end func
			+func top(): int
				ret me.data[0]
			end func
		end class
	end func
	
	class Edge()
		+var v: int
		+var dist: int
		+func init(v: int, dist: int): Edge
			do me.v :: v
			do me.dist :: dist
			ret me
		end func
	end class
end func