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.util.*;
import java.io.*;
public class Main {
	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	int datasize = 0;//????????°
	int datasize2 = 0;//???????????°
	int start = 0;
	int distance[];//???????????¢
	@SuppressWarnings("unchecked")
	static ArrayList<Edge>[]G = new ArrayList[100000];
	static int Infinity = 1500000000;
	public static void main(String []args){
		Main m = new Main();
	}
	public Main(){
		try{
			String input = reader.readLine();
			String []get = input.split(" ");
			datasize = Integer.parseInt(get[1]);
			datasize2 = Integer.parseInt(get[0]);
			start = Integer.parseInt(get[2]);
			distance = new int[datasize2];
			for(int z = 0;z < datasize2;z++){
				G[z] = new ArrayList<Edge>(0);
				this.distance[z] = Infinity;
			}
			for(int z = 0;z < datasize;z++){
				input = reader.readLine();
				get = input.split(" ");
				G[Integer.parseInt(get[0])].add(new Edge(Integer.parseInt(get[1]),Integer.parseInt(get[2])));
			}
			Explore();
			for(int z = 0;z < datasize2;z++){
				if(distance[z] != Infinity)System.out.println(distance[z]);
				else System.out.println("INF");
			}
		}catch(IOException e){
			
		}
	}
	public void Explore(){
		
		PriorityQueue<Candidate> candidates = new PriorityQueue<Candidate>();
		candidates.offer(new Candidate(start,0));
		distance[start] = 0;
		while(!candidates.isEmpty()){
			Candidate c = candidates.poll();
			int number = c.number;
			int d = c.d;
			if(distance[number] < d){
				continue;
			}
			List<Edge> edges = G[number];//No.????????????????????????????????´????????¢??????????????¨??????
			for(Edge ed : edges){
				if(distance[ed.go] > distance[number] + ed.cost){//?????????????????????????????¢>????????????+????????????????????????
					distance[ed.go] = distance[number]+ed.cost;
					candidates.offer(new Candidate(ed.go,distance[ed.go]));
				}
			}
		}
	}
	static class Candidate implements Comparable<Candidate>{//???????????¢????£??????????
		int number = -1;//?????????????????????
		int d = 0;//?????¢
		public Candidate(int number,int d){
			this.number = number;
			this.d = d;
		}
		@Override
		public int compareTo(Candidate o) {
			return d-o.d;
		}
	}static class Edge{
		int go;//??????????????????
		int cost;//?????¢
		Edge(int go,int cost){
			this.go = go;
			this.cost = cost;
		}
	}
}