
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <climits>

using namespace std;

map<string, vector<string>> listG;
map<string, int> color;     
map<string, int> dis;
map<string, string> parent;
vector<string> points;

void addPoint(string name) {
    if (listG.find(name) == listG.end()) {
        listG[name] = vector<string>();
        points.push_back(name);
        color[name] = -1;
        dis[name] = INT_MAX;
    }
}

void listInput(int e) {
    string u, v;
    for (int i = 0; i < e; i++) {
        cin >> u >> v;
        addPoint(u);
        addPoint(v);
        listG[u].push_back(v);
        listG[v].push_back(u);
    }
}

void BFS(string s) {
    queue<string> Q;
    Q.push(s);
    color[s] = 0;
    dis[s] = 0;

    while (!Q.empty()) {
        string u = Q.front();
        Q.pop();

        for (int i = 0; i < listG[u].size(); i++) {
            string v = listG[u][i];
            if (color[v] == -1) {
                Q.push(v);
                color[v] = 0;
                dis[v] = dis[u] + 1;
                parent[v] = u;
            }
        }
        color[u] = 1;
    }
}

void printRoute(string point, string source) {
    vector<string> route;
    string current = point;

    while (current != source) {
        route.push_back(current);
        current = parent[current];
    }
    route.push_back(source);

    for (int i = 0; i < route.size(); i++) {
        cout << route[i];
        if (i != route.size() - 1) {
            cout << " -> ";
        }
    }
}

int main() {
    int n, e;

    
    cout << "Enter total points and edges: ";
    if (!(cin >> n >> e)) return 0;

    listInput(e);

    while (points.size() < (size_t)n) {
        string name;
        cin >> name;
        addPoint(name);
    }

    string word, source;
    cin >> word >> source;
    addPoint(source);

    BFS(source);

    cout << "\n--------------------------------------------------\n";
    cout << "Campus Emergency Route Results\n";
    cout << "Assembly Point: " << source << "\n";
    cout << "--------------------------------------------------\n";

    for (int i = 0; i < points.size(); i++) {
        string point = points[i];

        if (point == source) {
            continue;
        }

        cout << "Point: " << point << " ";

        if (color[point] == -1) {
            cout << "Reachable: No Steps: - Route: No path exists" << endl;
        } else {
            cout << "Reachable: Yes Steps: " << dis[point] << " Route: ";
            printRoute(point, source);
            cout << endl;
        }
    }

    return 0;
}
