Improved Calculation Time With Using PriorityQueue