# Getting wrong answer on codechef but getting right output on my computer (Free ticket problem)

Here’s my solution:

``````import java.util.PriorityQueue;
import java.io.IOException;

class PriorityQueueNode implements Comparable<PriorityQueueNode> {
private int key;
private int nodeId;

public int getKey() {
return key;
}

public void setKey(int key) {
this.key = key;
}

public int getNodeId() {
return nodeId;
}

public void setNodeId(int nodeId) {
this.nodeId = nodeId;
}

@Override
public int compareTo(PriorityQueueNode o) {
return this.key < o.getKey()? 0: -1;
}

public PriorityQueueNode(int key, int nodeId){
this.key = key;
this.nodeId = nodeId;
}
}

class Graph {

public Graph(int nodesCount){
for(int i = 0; i < AdjacencyMatrix.length; i++){
for(int j = 0; j < nodesCount; j++){
}
}
}

}

public void createEdge(int node1, int node2, int distance){
}

public String toString(){
String ans = "";
for(int i = 0; i < AdjacencyMatrix.length; i++){
for(int j = 0; j < AdjacencyMatrix.length; j++){
ans += AdjacencyMatrix[i][j] + " ";
}
ans += "\n";
}
return ans;
}

public Integer getShortestPath(){
//insert all graph's nodes in the heap
//get the min from the heap
//change value of node if it is less than that of its current value
//repeat until the heap is empty
//insert all graph's nodes in the heap
PriorityQueue<PriorityQueueNode> priorityQueue = new PriorityQueue<PriorityQueueNode>();
/*for(int i = 1; i < AdjacencyMatrix.length; i++){
}*/

for(int i = 0; i < AdjacencyMatrix.length; i++){
ShortestPathArr[i] = 23665;
}
ShortestPathArr[0] = 0;

//get the min from the heap
PriorityQueueNode node = null;
while(!priorityQueue.isEmpty()){
node = priorityQueue.peek();
priorityQueue.remove(node);

int nodeId = node.getNodeId();

for(int i = 0; i < AdjacencyMatrix.length; i++){
}
}
}
}
return ShortestPathArr[ShortestPathArr.length-1];
}
}

class MainClass{
public static void main(String[] args){
try{

Graph graph = null;
String[] firstLineArr = firstLine.split(" ");
int citiesCount = Integer.parseInt(firstLineArr[0]);
int edgesCount = Integer.parseInt(firstLineArr[1]);

//create graph as adjacency matrix with no. of cities
graph = new Graph(citiesCount);

for(int i = 0; i < edgesCount; i++){

String[] currentLineArr = currentLine.split(" ");
int city1 = Integer.parseInt(currentLineArr[0]);
int city2 = Integer.parseInt(currentLineArr[1]);
int distance = Integer.parseInt(currentLineArr[2]);

graph.createEdge(city1, city2, distance);
}
System.out.print(graph.getShortestPath());
} catch(IOException e){
e.printStackTrace();
}
}
}``````