// Author: Adrian Kuegel // Date: July 10th, 2009 // Complexity: O(n * h) import java.util.*; import java.io.*; class Edge { private int dest, c; public Edge(int destination, int cost) { dest = destination; c = cost; } public int getDestination() { return dest; } public int getCost() { return c; } } public class hotel { public static void main(String [] args) throws Exception { BufferedReader br = new BufferedReader(new FileReader("hotel.in")); int n; boolean [] has_hotel = new boolean[10000]; int [] d = new int[10000]; int [] Q = new int[101]; ArrayList [] r = new ArrayList[601]; for (int i=0; i<601; ++i) r[i] = new ArrayList(); ArrayList [] adj = new ArrayList[10000]; for (int i=0; i<10000; ++i) adj[i] = new ArrayList(); while((n = Integer.parseInt(br.readLine())) != 0) { for (int i=0; i 0) { strTok = new StringTokenizer(br.readLine()); int a = Integer.parseInt(strTok.nextToken()) - 1; int b = Integer.parseInt(strTok.nextToken()) - 1; int dist = Integer.parseInt(strTok.nextToken()); adj[a].add(new Edge(b, dist)); adj[b].add(new Edge(a, dist)); } Q[0] = 0; int l = 1, res = -1; while(l > 0 && has_hotel[n-1]) { ++res; for (int i=0; i<=600; ++i) r[i].clear(); for (int i=0; i