Helper to compute total weight of edges in the spanning tree.
| 36 | |
| 37 | // Helper to compute total weight of edges in the spanning tree. |
| 38 | float ComputeTreeWeight(const SpanningTree& tree, |
| 39 | const std::vector<std::pair<int, int>>& edges, |
| 40 | const std::vector<float>& weights) { |
| 41 | float total = 0; |
| 42 | for (size_t i = 0; i < edges.size(); ++i) { |
| 43 | int u = edges[i].first; |
| 44 | int v = edges[i].second; |
| 45 | // Check if this edge is in the tree (either direction). |
| 46 | if (tree.parents[u] == v || tree.parents[v] == u) { |
| 47 | total += weights[i]; |
| 48 | } |
| 49 | } |
| 50 | return total; |
| 51 | } |
| 52 | |
| 53 | TEST(SpanningTree, Nominal) { |
| 54 | // Triangle: edges with weights 1, 2, 3. |