We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Roads and Libraries
- Discussions
Roads and Libraries
Roads and Libraries
Sort by
recency
|
28 Discussions
|
Please Login in order to post a comment
Time limit exceeded using c#, i dont know why. I using Union Find,
typical island count graph problem
1, build the graph 2, traverser the graph, found the count of groups 3. calculate the cost
Answer in Python
my JAVA code but 1 wrong and some time exceed
C++ using Union Find / Disjoint Sets. Every city starts with a library, and for each edge, if the two nodes aren't already in the same network, we connect them, replacing
b
's library with a road intoa
's network instead.Here's a great video explaining the basic intuition behind Union Find. https://www.youtube.com/watch?v=ayW5B2W9hfo&pp=ygUKdW5pb24gZmluZA%3D%3D It's a very simple data structure--don't be intimidated by the large
class UnionFind
s you'll see in some of the other answers here.