static void Main(string[] args) { int n = 100; bool allConnected = false; Random rnd = new Random(); var uf = new WeightedQuickUnion(n); for (int i = 0; i < 3 * n; i++) { int x = rnd.Next(0, n); int y = rnd.Next(0, n); if (!uf.Connected(x, y)) { uf.Union(x, y); Console.WriteLine($"({x}, {y}) {uf.Count()}"); if (uf.Count() == 1) { allConnected = true; break; } } } Console.WriteLine(allConnected); Console.ReadLine(); }
static void Main(string[] args) { var uf = new WeightedQuickUnion(10); uf.Union(0, 4); uf.Union(2, 5); uf.Union(2, 6); uf.Union(4, 2); uf.Union(1, 7); uf.Union(7, 3); uf.Union(3, 8); uf.Union(9, 3); for (int i = 0; i < 10; i++) { Console.WriteLine($"max for {i} is {uf.FindMax(i)}"); } Console.ReadLine(); }