public double findMaxBranching(int numberOfNodes, double[][] graph,
			Collection<SimpleWeightedEdge> mst, DisjointSets partition) {
		// Clear the list of all edges.
		edges.clear();
		// Clear MST.
		mst.clear();
		// Add feasible edges with their weights to the list.
		for (int from = 0; from < numberOfNodes; ++from) {
			for (int to = 0; to < numberOfNodes; ++to) {
				if (from == to)
					// Skip auto-cycle arcs.
					continue;
				if (Double.isNaN(graph[from][to]))
					// Skip inexistent edges.
					continue;
				if (onlyPositiveEdges && graph[from][to] < 0d)
					// Skip negative edges, when required so.
					continue;
				// Feasible edge.
				edges.add(new SimpleWeightedEdge(from, to, graph[from][to]));
			}
		}

		// Sort edges in the inverse order of their weights.
		Collections.sort(edges, comp);

		// Initialize the disjoint sets (one component for each node).
		partition.clear(numberOfNodes);

		// Greedily select edges while avoiding cycles.
		double totalWeight = 0d;
		int numComponents = numberOfNodes;
		for (SimpleWeightedEdge edge : edges) {
			/*
			 * If edge connects two components, merge them and add this edge to
			 * the MST.
			 */
			if (partition.unionElements(edge.from, edge.to)) {
				// Add edge to the tree.
				mst.add(edge);
				// Account for its weight.
				totalWeight += edge.weight;
				// Decrement number of components.
				--numComponents;
				// Stop, if achieved the required number of components.
				if (numComponents <= minComponents)
					break;
			}
		}

		// Return the weight of the created tree.
		return totalWeight;
	}