Task: | Shortest Routes I |
Sender: | Nallue |
Submission time: | 2024-10-06 13:52:56 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | WRONG ANSWER | 0.00 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.00 s | details |
#7 | WRONG ANSWER | 0.00 s | details |
#8 | WRONG ANSWER | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.00 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | WRONG ANSWER | 0.00 s | details |
#13 | WRONG ANSWER | 0.00 s | details |
#14 | WRONG ANSWER | 0.00 s | details |
#15 | WRONG ANSWER | 0.00 s | details |
#16 | WRONG ANSWER | 0.00 s | details |
#17 | WRONG ANSWER | 0.01 s | details |
#18 | WRONG ANSWER | 0.00 s | details |
Compiler report
input/code.cpp: In function 'int minDistance(int*, bool*)': input/code.cpp:24:12: warning: 'min_index' may be used uninitialized in this function [-Wmaybe-uninitialized] 24 | return min_index; | ^~~~~~~~~ input/code.cpp: In function 'void dijkstra(int (*)[9], int)': input/code.cpp:77:26: warning: 'min_index' may be used uninitialized in this function [-Wmaybe-uninitialized] 77 | && dist[u] != INT_MAX | ~~~~~~^
Code
// C++ program for Dijkstra's single source shortest path // algorithm. The program is for adjacency matrix // representation of the graph #include <iostream> using namespace std; #include <limits.h> // Number of vertices in the graph #define V 9 // A utility function to find the vertex with minimum // distance value, from the set of vertices not yet included // in shortest path tree int minDistance(int dist[], bool sptSet[]) { // Initialize min value int min = INT_MAX, min_index; for (int v = 0; v < V; v++) if (sptSet[v] == false && dist[v] <= min) min = dist[v], min_index = v; return min_index; } // A utility function to print the constructed distance // array void printSolution(int dist[]) { cout << "Vertex \t Distance from Source" << endl; for (int i = 0; i < V; i++) cout << i << " \t\t\t\t" << dist[i] << endl; } // Function that implements Dijkstra's single source // shortest path algorithm for a graph represented using // adjacency matrix representation void dijkstra(int graph[V][V], int src) { int dist[V]; // The output array. dist[i] will hold the // shortest // distance from src to i bool sptSet[V]; // sptSet[i] will be true if vertex i is // included in shortest // path tree or shortest distance from src to i is // finalized // Initialize all distances as INFINITE and stpSet[] as // false for (int i = 0; i < V; i++) dist[i] = INT_MAX, sptSet[i] = false; // Distance of source vertex from itself is always 0 dist[src] = 0; // Find shortest path for all vertices for (int count = 0; count < V - 1; count++) { // Pick the minimum distance vertex from the set of // vertices not yet processed. u is always equal to // src in the first iteration. int u = minDistance(dist, sptSet); // Mark the picked vertex as processed sptSet[u] = true; // Update dist value of the adjacent vertices of the // picked vertex. for (int v = 0; v < V; v++) // Update dist[v] only if is not in sptSet, // there is an edge from u to v, and total // weight of path from src to v through u is // smaller than current value of dist[v] if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] + graph[u][v] < dist[v]) dist[v] = dist[u] + graph[u][v]; } // print the constructed distance array printSolution(dist); } // driver's code int main() { /* Let us create the example graph discussed above */ int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 }, { 4, 0, 8, 0, 0, 0, 0, 11, 0 }, { 0, 8, 0, 7, 0, 4, 0, 0, 2 }, { 0, 0, 7, 0, 9, 14, 0, 0, 0 }, { 0, 0, 0, 9, 0, 10, 0, 0, 0 }, { 0, 0, 4, 14, 10, 0, 2, 0, 0 }, { 0, 0, 0, 0, 0, 2, 0, 1, 6 }, { 8, 11, 0, 0, 0, 0, 1, 0, 7 }, { 0, 0, 2, 0, 0, 0, 6, 7, 0 } }; // Function call dijkstra(graph, 0); return 0; } // This code is contributed by shivanisinghss2110
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
10 20 8 5 1 9 10 2 7 9 8 9 8 8 ... |
correct output |
---|
0 9 11 20 13 14 19 29 27 29 |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 2
Verdict: WRONG ANSWER
input |
---|
10 20 5 6 4 5 1 7 7 4 4 7 8 1 ... |
correct output |
---|
0 7 9 17 15 17 21 22 25 30 |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 3
Verdict: WRONG ANSWER
input |
---|
10 20 1 4 1 4 2 1 9 10 1 1 2 4 ... |
correct output |
---|
0 2 11 1 2 7 16 18 12 13 |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 4
Verdict: WRONG ANSWER
input |
---|
10 20 6 3 5 7 5 8 5 1 8 8 9 5 ... |
correct output |
---|
0 5 9 18 22 10 14 23 27 36 |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 5
Verdict: WRONG ANSWER
input |
---|
10 20 8 9 3 2 3 8 10 5 3 2 5 3 ... |
correct output |
---|
0 8 16 18 11 17 24 23 16 26 |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 6
Verdict: WRONG ANSWER
input |
---|
100000 200000 18000 18001 426710313 73018 73012 558438094 87726 87671 355171790 53170 53171 869493690 ... |
correct output |
---|
0 479659405 1165315262 1854343... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 7
Verdict: WRONG ANSWER
input |
---|
100000 200000 26504 26450 258578924 49543 49544 28958186 75174 75175 89459846 39175 39228 119699475 ... |
correct output |
---|
0 655556128 1413395076 1814086... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 8
Verdict: WRONG ANSWER
input |
---|
100000 200000 39477 39413 773046299 69758 69759 558754983 23279 23280 142570619 61416 61479 874921013 ... |
correct output |
---|
0 269736525 626115013 70199222... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 9
Verdict: WRONG ANSWER
input |
---|
100000 200000 76662 76636 844365635 73339 73342 755006676 89878 89879 396562588 18801 18781 954807004 ... |
correct output |
---|
0 598585836 1267139909 1803859... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 10
Verdict: WRONG ANSWER
input |
---|
100000 200000 11724 11725 818399968 33244 33197 722525474 65530 65531 483965413 62405 62454 199581867 ... |
correct output |
---|
0 387990617 441010945 92441292... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 11
Verdict: WRONG ANSWER
input |
---|
100000 200000 1 2 1 1 3 1 1 4 1 1 5 1 ... |
correct output |
---|
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 12
Verdict: WRONG ANSWER
input |
---|
100000 99999 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 ... |
correct output |
---|
0 1000000000 2000000000 300000... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 13
Verdict: WRONG ANSWER
input |
---|
1 1 1 1 1 |
correct output |
---|
0 |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 14
Verdict: WRONG ANSWER
input |
---|
99999 149997 1 2 1 2 3 1 3 4 1 4 5 1 ... |
correct output |
---|
0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 ... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 15
Verdict: WRONG ANSWER
input |
---|
99997 149994 1 3 3 3 5 3 5 7 3 7 9 3 ... |
correct output |
---|
0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 16
Verdict: WRONG ANSWER
input |
---|
60003 120000 1 2 30010 1 3 30010 1 4 30010 1 5 30010 ... |
correct output |
---|
0 30010 30010 30010 30010 3001... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 17
Verdict: WRONG ANSWER
input |
---|
60003 120000 1 2 30010 1 3 30010 1 4 30010 1 5 30010 ... |
correct output |
---|
0 30010 30010 30010 30010 3001... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |
Test 18
Verdict: WRONG ANSWER
input |
---|
100000 149997 1 50000 99997 1 49999 99995 1 49998 99993 1 49997 99991 ... |
correct output |
---|
0 1 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
Vertex Distance from Source 0 0 1 4 2 12 3 19 ... Truncated |