Language: Java

import java.util.*;


public class LazyPrimsAdjacencyList {

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
  static class Edge implements Comparable <Edge> {
    int from, to, cost;
    public Edge(int from, int to, int cost) {
      this.from = from;
      this.to = to;
      this.cost = cost;
    }
    @Override public int compareTo(Edge other) {
      return cost - other.cost;
    }
  }
  
  // Graph must be undirected!
  public static Long prims(Map <Integer, List<Edge>> graph, int n) {
    
    if (graph == null) return null;
    
    long sum = 0, nodesVisited = 1;
    boolean[] visited = new boolean[n];
    PriorityQueue <Edge> pq = new PriorityQueue<>();
    
    // Add initial set of edges to the pq
    List <Edge> edges = graph.get(0);
    if (edges == null || edges.size() == 0) return null;
    for(Edge edge : edges) pq.offer(edge);
    visited[0] = true;

    // Loop while the MST is not complete
    while ( nodesVisited != n && !pq.isEmpty() ) {
      Edge edge = pq.poll();
      if (!visited[edge.to]) {
        
        // Add edges to nodes we have not yet visited
        edges = graph.get(edge.to);
        if (edges == null || edges.size() == 0) return null;
        for (Edge e : edges) 
          if (!visited[e.to])
            pq.offer(e);

        visited[edge.to] = true;
        sum += edge.cost;
        nodesVisited++;

      }
    }
    
    // Check if MST spans entire graph
    if (nodesVisited == n) return sum;
    return null;

  }

  // Example usage
  public static void main(String[] args) {
    
    // Contains tuples of (from, to, weight)
StringTokenizer st = new StringTokenizer(br.readLine());
 final int NUM_NODES = Integer.parseInt(st.nextToken());
final int edge = Integer.parseInt(st.nextToken());

int[][] edges= new int[edge][edge];

for (int i = 1; i <= edge; i++) {
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			graph[a][b]  = c-1;

		}
    


   

    // Setup graph as adjacency list
    Map <Integer, List<Edge>> graph = new HashMap<>();
    for (int i = 0; i < NUM_NODES; i++) graph.put(i, new ArrayList<>());
    for ( int[] tuple : edges ) {
      int from = tuple[0];
      int to = tuple[1];
      int cost = tuple[2];
      Edge edge = new Edge(from, to, cost);
      Edge revEdge = new Edge(to, from, cost);
      graph.get(from).add(edge);
      graph.get(to).add(revEdge);
    }

    Long mstCost = prims(graph, NUM_NODES);
    System.out.println("MST cost: " + mstCost);

  }

}

Compiler output:
Main.java:4: error: class LazyPrimsAdjacencyList is public, should be declared in a file named LazyPrimsAdjacencyList.java
public class LazyPrimsAdjacencyList {
       ^
Main.java:6: error: cannot find symbol
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       ^
  symbol:   class BufferedReader
  location: class LazyPrimsAdjacencyList
Main.java:6: error: cannot find symbol
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                               ^
  symbol:   class BufferedReader
  location: class LazyPrimsAdjacencyList
Main.java:6: error: cannot find symbol
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                                                  ^
  symbol:   class InputStreamReader
  location: class LazyPrimsAdjacencyList
Main.java:75: error: cannot find symbol
			graph[a][b]  = c-1;
			^
  symbol:   variable graph
  location: class LazyPrimsAdjacencyList
Main.java:90: error: variable edge is already defined in method main(String[])
      Edge edge = new Edge(from, to, cost);
           ^
6 errors