#include <iostream>
#include <iostream>
#include <vector>
#include <queue> 
using namespace std;

const int MAX = 100;

vector<int> graph[MAX];
bool visited[MAX];
int priorityLevel[MAX];

void bfs(int start, int nodes) {
    if (start < 0 || start >= nodes) {
        cout << "Invalid burst location\n";
        return;
    }

    queue<int> q;
    q.push(start);
    visited[start] = true;

    cout << "Affected Areas:\n";

    while (!q.empty()) {
        int node = q.front();
        q.pop();

        cout << "Area " << node << " (Priority: " << priorityLevel[node] << ")\n";

        for (int neighbor : graph[node]) {
            if (!visited[neighbor]) {
                visited[neighbor] = true;
                q.push(neighbor);
            }
        }
    }
}

int main() {
    int nodes, edges;
    cin >> nodes >> edges;

    if (nodes > MAX || nodes <= 0) {
        cout << "Invalid number of nodes\n";
        return 1;
    }

    // Reset arrays
    for(int i = 0; i < MAX; i++) {
        visited[i] = false;
        graph[i].clear();
        priorityLevel[i] = 0;
    }

    for (int i = 0; i < edges; i++) {
        int u, v;
        cin >> u >> v;
        if (u >= 0 && u < nodes && v >= 0 && v < nodes) {
            graph[u].push_back(v);
            graph[v].push_back(u);
        }
    }

    for (int i = 0; i < nodes; i++) {
        cin >> priorityLevel[i];
    }

    int burstLocation;
    cin >> burstLocation;

    bfs(burstLocation, nodes);

    return 0;
}
