#include #include "Graph.h" #include "Hash.h" #include "Maze.h" #include "test_utilities.h" // Given a Maze m and a vertex id v, return a HashTable H // such that for each vertex w reachable from v, H[w] is the distance // (length of shortest path) from v to w // (and for any other vertex H[w] is not set). // // Your routine should run in linear time. // YOUR CODE HERE HashTable find_distances_from(const Maze &m, int v) { // YOUR CODE HERE } int main() { Maze m; // read the maze in text format from stdin std::cin >> m; // compute distances from the start vertex HashTable distances; distances = find_distances_from(m, m.get_start_vertex()); // output the distances mod 10 const int mod = 4; static char labels[mod] = { '0', '1', '2', '#' }; Array vertices = m.graph().vertices(); for (int i = 0; i < vertices.size(); ++i) { int v = vertices[i]; if (v != m.get_start_vertex() && v != m.get_end_vertex() && distances.exists(v)) { Array loc = m.loc_of_vertex(v); m.set_text_at(loc[0], loc[1], labels[distances[v] % mod]); } } std::cout << m << std::endl; // output the distance from start to end if (distances.exists(m.get_end_vertex())) std::cout << "Distance from start to end is " << distances[m.get_end_vertex()] << std::endl; else std::cout << "No path from start to end." << std::endl; }