content: import java.util.*;
  
  class Graph {
      private int V; // Number of vertices
      private List<List<Node>> adj; // Adjacency list
  
      public Graph(int V) {
          this.V = V;
          adj = new ArrayList<>(V);
          for (int i = 0; i < V; i++) {
              adj.add(new ArrayList<>());
          }
      }
  
      // Add an edge to the graph
      public void addEdge(int source, int destination, int weight) {
          Node node = new Node(destination, weight);
          adj.get(source).add(node);
      }
  
      public void dijkstra(int source) {
          int[] distance = new int[V];
          Arrays.fill(distance, Integer.MAX_VALUE);
          distance[source] = 0;
  
          PriorityQueue<Node> pq = new PriorityQueue<>(V, Comparator.comparingInt(node -> node.weight));
          pq.add(new Node(source, 0));
  
          while (!pq.isEmpty()) {
              int u = pq.poll().vertex;
  
              for (Node neighbor : adj.get(u)) {
                  int v = neighbor.vertex;
                  int w = neighbor.weight;
  
                  if (distance[u] != Integer.MAX_VALUE && distance[u] + w < distance[v]) {
                      distance[v] = distance[u] + w;
                      pq.add(new Node(v, distance[v]));
                  }
              }
          }
  
          // Print the shortest distances from the source
          System.out.println("Shortest distances from source vertex " + source + ":");
          for (int i = 0; i < V; i++) {
              System.out.println("Vertex " + i + ": " + distance[i]);
          }
      }
  
      private static class Node {
          int vertex;
          int weight;
  
          Node(int vertex, int weight) {
              this.vertex = vertex;
              this.weight = weight;
          }
      }
  }
  
  public class DijkstraAlgorithm {
      public static void main(String[] args) {
          int V = 6; // Number of vertices
          Graph graph = new Graph(V);
  
          // Add edges and their weights
          graph.addEdge(0, 1, 2);
          graph.addEdge(0, 2, 4);
          graph.addEdge(1, 2, 1);
          graph.addEdge(1, 3, 7);
          graph.addEdge(2, 4, 3);
          graph.addEdge(3, 4, 1);
          graph.addEdge(3, 5, 5);
          graph.addEdge(4, 5, 2);
  
          int source = 0; // Source vertex
          graph.dijkstra(source);
      }
  }
  