Try working in reverse order.
Add the edges one by one and use a disjoint set data structure to find when the set becomes connected.
More Related Contents:
- Sample Directed Graph and Topological Sort Code [closed]
- Fast algorithm to calculate n! / (q!)^r
- Deciding a Big-O notation for an algorithm
- What is the fastest search algorithm for a list with names and numbers
- Algorithm to divide a given number in two proportions by one of the component of that number
- Java – class, get new array of objects
- Why does this recursive quick sort program not work? [closed]
- What’s the best way to build a string of delimited items in Java?
- Java lambdas 20 times slower than anonymous classes
- Connect 4 check for a win algorithm
- How to check if two words are anagrams
- Prime numbers by Eratosthenes quicker sequential than concurrently?
- What would be the fastest method to test for primality in Java?
- Generating all possible permutations of a list recursively
- Parallel execution of directed acyclic graph of tasks
- What is a good solution for calculating an average where the sum of all values exceeds a double’s limits?
- All possible combinations of an array
- Intersection of two strings in Java
- How to find all permutations of a given word in a given text?
- What is a non recursive solution for Fibonacci-like sequence in Java?
- What is the sorting algorithm for Java [closed]
- best way to pick a random subset from a collection?
- Algorithm for 2D Raytracer
- Flatten nested arrays in java
- Generate Random Numbers in Array [duplicate]
- Algorithm – How to delete duplicate elements in a list efficiently?
- Determine the most common occurrence in an array
- Fastest way of finding the middle value of a triple?
- Interview question – Search in sorted array X for index i such that X[i] = i
- Example of O(n!)?