Untitled

 avatar
unknown
java
5 months ago
1.0 kB
3
Indexable
import java.util.*;
import java.io.*;

public class TopologicalSortExample {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        // Step 1: Initialize adjacency list and in-degree array
        List<Integer>[] adj = new ArrayList[8]; // Adjacency list for graph (1-indexed)
        for (int i = 1; i <= 7; i++) {
            adj[i] = new ArrayList<>();
        }

        adj[1].add(7);
        adj[1].add(4);
        adj[2].add(1);
        adj[3].add(4);
        adj[3].add(5);

        PriorityQueue<Integer> queue = new PriorityQueue<>();

 
    }

    // Helper methods for input handling
    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }

    static int readInt() throws IOException {
        return Integer.parseInt(next());
    }
}
Editor is loading...
Leave a Comment