C++代码:遍历最小生成树并删除权重小于0.003的边
struct Edge
{
int src, tgt;
float weight;
};
std::vector<Edge> result;
// 遍历最小生成树 'result',删除权重小于 0.003 的边
for (int i = 0; i < result.size(); i++) {
if (result[i].weight < 0.003) {
result.erase(result.begin() + i);
i--; // 删除元素后需要将索引减 1,避免跳过元素
}
}
原文地址: https://www.cveoy.top/t/topic/fMHE 著作权归作者所有。请勿转载和采集!