Problem: For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path).

Constraints

* 1 ≤ |V| ≤ 100000
* 0 ≤ di ≤ 10000
* 0 ≤ |E| ≤ 500000
* There are no parallel edges
* There are no self-loops

Input

An edge-weighted graph G (V, E) and the source r.


|V| |E| r
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1


|V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the source of the graph.

si and ti represent source and target vertices of i-th edge (directed) and di represents the cost of the i-th edge.

Output

Print the costs of SSSP in the following format.


c0
c1
:
c|V|-1


The output consists of |V| lines. Print the cost of the shortest path from the source r to each vertex 0, 1, ... |V|-1 in order. If there is no path from the source to a vertex, print INF.

Examples

Input

4 5 0
0 1 1
0 2 4
1 2 2
2 3 1
1 3 5


Output

0
1
3
4


Input

4 6 1
0 1 1
0 2 4
2 0 1
1 2 2
3 1 1
3 2 5


Output

3
0
2
INF

Solution (in JAVA):

Solution:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	int V,E,r;
	List<ArrayList<P>> graph;
	long[] ans;

	private class P{
		int n,c;
		public P(int n,int c){
			this.n = n;
			this.c = c;
		}
	}

	private class D implements Comparable<D>{
		int n;
		long c;
		public D(int n,long c){
			this.n = n;
			this.c = c;
		}

		public int compareTo(D d){
			if(this.c - d.c < 0){
				return -1;
			}else if(this.c - d.c > 0){
				return 1;
			}else{
				return 0;
			}
		}
	}

	public void dijkstra(int s){
		boolean[] used = new boolean[V];

		PriorityQueue<D> pq = new PriorityQueue<D>();
		pq.add(new D(r,0));
		while(pq.size() > 0){
			D d = pq.poll();

			used[d.n] = true;
			ans[d.n] = Math.min(ans[d.n],d.c);

			for(P i : graph.get(d.n)){
				if(used[i.n])continue;
				pq.add(new D(i.n,d.c + i.c));
			}
		}
	}

	public void solve() {
		V = nextInt();
		E = nextInt();
		r = nextInt();

		graph = new ArrayList<ArrayList<P>>();
		ans = new long[V];

		for(int i = 0;i < V;i++){
			graph.add(new ArrayList<P>());
		}

		for(int i = 0;i < V;i++){
			ans[i] = Long.MAX_VALUE;
		}

		for(int i = 0;i < E;i++){
			int s = nextInt();
			int t = nextInt();
			int d = nextInt();

			graph.get(s).add(new P(t,d));
		}

		dijkstra(r);

		for(int i = 0;i < V;i++){
			if(ans[i] == Long.MAX_VALUE)out.println("INF");
			else out.println(ans[i]);
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}