implement bfs multi-target distance calculation to nearest winning state

This commit is contained in:
2026-02-25 01:15:47 +01:00
parent b9e3ab8d2d
commit fd58f217c6
11 changed files with 208 additions and 37 deletions

32
include/distance.hpp Normal file
View File

@ -0,0 +1,32 @@
#ifndef __DISTANCE_HPP_
#define __DISTANCE_HPP_
#include "config.hpp"
#include <cstddef>
#include <vector>
struct DistanceResult {
// distances[n] = distance from n to target
std::vector<int> distances;
// parents[n] = next node on the path from n to target
std::vector<std::size_t> parents;
// nearest_target[n] = closest target node to n
std::vector<std::size_t> nearest_targets;
auto Clear() -> void;
auto Empty() -> bool;
};
auto CalculateDistances(
std::size_t node_count,
const std::vector<std::pair<std::size_t, std::size_t>> &edges,
const std::vector<std::size_t> &targets) -> DistanceResult;
auto GetPath(const DistanceResult &result, std::size_t source)
-> std::vector<std::size_t>;
#endif