Hi,
I'm newbie. I submitted my code, but it was wrong. Then, I copied the test case into the TEST CASE and tapped "Run Code".
Strangely, the answer is right????? Has anyone encountered this situation yet?


This is my code:
#define MAX 100
#define INFINITY 9999999
int queue[MAX*(MAX-1)/2];
int topQueue = -1;
int front = 0;
int queueItemCount = 0;
void insert(int vertex) {
queue[++topQueue] = vertex;
queueItemCount ++;
}
void removeQueue() {
queueItemCount --;
front++;
}
int getData() {
return queue[front];
}
int queue2[MAX*(MAX-1)/2];
void insert2(int i) {
queue2[topQueue] = i;
}
int getData2() {
return queue2[front];
}
int findCheapestPrice(int n, int** flights, int flightsSize, int* flightsColSize, int src, int dst, int K){
int M[n][n];
for (int i=0 ; i<n; i++)
for ( int j=0; j<n; j++)
M[i][j] = 0;
for (int i=0; i<flightsSize; i++){
M[flights[i][0]][flights[i][1]] = flights[i][2];
}
bool visited[n];
int shortest_path[n];
for (int i = 0; i<n; i++) {
shortest_path[i] = INFINITY;
visited[i] = false;
}
visited[src] = true;
for (int j= 1; j<n; j++) {
insert(j);
insert2(K-1);
if (M[src][j] != 0)
shortest_path[j] = M[src][j];
}
// printf("%d",getData2());
// printf("%d", queueItemCount);
// for (int i=0; i<n; i++)
// printf("%d ", shortest_path[i]);
// printf("\n");
while (queueItemCount != 0 && getData2()>=0) {
int next = getData();
// update cac khoang cach
// for (int i=0; i<n; i++)
// printf("%d ", shortest_path[i]);
//printf("\n");
for (int j=0; j<n; j++)
if (M[next][j] != 0) {
if (shortest_path[next] + M[next][j] < shortest_path[j])
shortest_path[j] = shortest_path[next] + M[next][j];
}
//if (visited[
if (visited[next]) {
removeQueue();
}
else {
visited[next] = true;
for (int j=0; j<n; j++)
if (M[next][j] != 0){
insert(j);
insert2(getData2()-1);
}
}
}
if (shortest_path[dst] == INFINITY)
return -1;
else
return shortest_path[dst];
}Thanks for your help!