import java.io.*; import java.util.*; public class cabling { static double totalLength = 0; static PriorityQueue edgeHeap = new PriorityQueue(); static Hashtable houses = new Hashtable(); public static void main(String[] argv) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); double cableLength = Double.parseDouble(in.readLine().trim()); int nHouses = Integer.parseInt(in.readLine().trim()); for(int i=0;i 0){ Edge e = edgeHeap.remove(); if(houses.containsKey(e.a.name) || houses.containsKey(e.b.name)) addEdge(e); } if (totalLength > cableLength) System.out.println("Not enough cable"); else System.out.printf("Need %.1f miles of cable\n", totalLength); } static void addEdge(Edge e){ System.err.println("addedge "+e.a.name+"-"+e.b.name+" "+e.weight); totalLength+=e.weight; if(houses.containsKey(e.a.name)){ System.err.println("reached node "+e.a.name); for(Edge i:e.a.edges) edgeHeap.add(i); houses.remove(e.a.name); } if(houses.containsKey(e.b.name)){ System.err.println("reached node "+e.b.name); for(Edge i:e.b.edges) edgeHeap.add(i); houses.remove(e.b.name); } } } class Node { String name; boolean isIn = false; HashSet edges = new HashSet(); Node(String name){ this.name = name; } public String toString(){ return "Node:"+name; } } class Edge implements Comparable { Node a; Node b; Double weight; Edge(Node a, Node b, double weight){ this.a = a; this.b = b; this.weight = weight; } public int compareTo(Edge o){ return weight.compareTo(o.weight); } public String toString(){ return a.name+"--"+b.name+"("+weight+")"; } }