From 77f06663b95c85adb3a1f27234aeb03045e527d7 Mon Sep 17 00:00:00 2001 From: krishnaawasthi-26 Date: Sun, 29 Jun 2025 19:47:46 +0530 Subject: [PATCH] Update dijkstra.cpp --- graph/dijkstra.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/graph/dijkstra.cpp b/graph/dijkstra.cpp index a7621456009..aeae6b944c0 100644 --- a/graph/dijkstra.cpp +++ b/graph/dijkstra.cpp @@ -156,9 +156,24 @@ int main() { int vertices = int(), edges = int(); std::cout << "Enter the number of vertices : "; std::cin >> vertices; + + if (vertices == 0) { + std::cout << "Graph has no vertices. Nothing to compute." << std::endl; // case if there is no vertices there will be no hence we have nothing to compute + return 0; + } + std::cout << "Enter the number of edges : "; std::cin >> edges; + if(edges==0){ + std::cout<<"No edges in the graph. All nodes are isolated.\n"; // case if there is no edge hence the graph is disconnected hence we can't find the shortest path between two nodes + return 0; + } + if(edges<0 || vertices<0){ + std::cout<<"Input is invalid "; + return 0; + } + std::vector>> adj( vertices, std::vector>());