public static void main(String[] args) throws FileNotFoundException, IOException {
		long startTime = System.nanoTime();
		BufferedReader br = new BufferedReader(new FileReader("prim_greedy.txt"));
		String[] splitLine = br.readLine().trim().split("(\\s)+");

		int numV =  Integer.parseInt(splitLine[0]);
		int numE =  Integer.parseInt(splitLine[1]);		
		int adjmat[][] = new int[numV][numV];// adjadjmat initializing, cost more but easy to organize
		for(int i = 0; i < adjmat.length; i++){
			for(int j = 0; j < adjmat.length; j++){
				adjmat[i][j] = 1000000;
			}
		}	
		int v1,v2,weight;	

		String line;
		while((line = br.readLine())!=null){
			splitLine = line.trim().split("(\\s)+");
			v1 = Integer.parseInt(splitLine[0])-1;
			v2 = Integer.parseInt(splitLine[1])-1;
			weight = Integer.parseInt(splitLine[2]);	
			adjmat[v1][v2] = weight;
			adjmat[v2][v1] = weight;
		}
		br.close();		

		// creating adjlist
		List<Edge>[] adjlist = new List[numV];
		for (int i = 0; i < numV; i++){
			adjlist[i] = new ArrayList<Edge>();// each row is an arraylist
			for (int j = 0; j < numV; j++) {
				if (adjmat[i][j] < 1000000) {
					adjlist[i].add(new Edge(j, adjmat[i][j]));
				}
			}
		}
		primHeap(adjlist);
		long stopTime = System.nanoTime();
		System.out.println(stopTime-startTime);		

	}