the previous one was not working. Priorityqueue and hashmap corrected