#include using namespace std; struct Node { int first_atlas = INT_MAX; int first_our = INT_MAX; vector conn; bool final = false; }; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); size_t N, M, F, T, S; cin >> N >> M >> F >> T >> S; vector nodes(2 * N); for (size_t i = 0; i < M; ++i) { size_t f, t; cin >> f >> t; nodes[2 * f + 1].conn.push_back(2 * t); nodes[2 * f].conn.push_back(2 * t + 1); nodes[2 * t + 1].conn.push_back(2 * f); nodes[2 * t].conn.push_back(2 * f + 1); } nodes[F * 2].final = true; nodes[F * 2 + 1].final = true; // atlas { std::queue q; q.push(T * 2); nodes[q.front()].first_atlas = 0; while (q.size()) { auto next = q.front(); q.pop(); auto f_at = nodes[next].first_atlas; //cout << "at" << f_at << " " << next/2 << " " << next % 2 << endl; for (auto c: nodes[next].conn) { if (nodes[c].first_atlas == INT_MAX){ nodes[c].first_atlas = f_at + 1; q.push(c); } } } } // our { std::queue q; q.push(S * 2); nodes[q.front()].first_our = 0; while (q.size()) { auto next = q.front(); q.pop(); auto f_our = nodes[next].first_our; if (nodes[next].final) { cout << f_our << endl; exit(0); } //cout << "our" << f_our << " " << next/2 << " " << next % 2 << endl; if (f_our >= nodes[next].first_atlas) { continue; } for (auto c: nodes[next].conn) { if (nodes[c].first_our == INT_MAX){ nodes[c].first_our = f_our + 1; q.push(c); } } { // wait size_t c = next ^ 1; if (nodes[c].first_our == INT_MAX){ nodes[c].first_our = f_our + 1; q.push(c); } } } } cout << "death" << endl; return 0; }