#include #include #include using std::vector; using std::stack; using std::pair; int reach(vector > &adj, int x, int y) { vector visited(adj.size()); stack st; st.push(x); while(!st.empty()) { int v = st.top(); if (v == y) return 1; st.pop(); visited[v] = true; int s = adj[v].size(); for (int i = 0; i < s; i++) { int w = adj[v][i]; if (!visited[w]) st.push(w); } } return 0; } int main() { size_t n, m; std::cin >> n >> m; vector > adj(n, vector()); for (size_t i = 0; i < m; i++) { int x, y; std::cin >> x >> y; adj[x - 1].push_back(y - 1); adj[y - 1].push_back(x - 1); } int x, y; std::cin >> x >> y; std::cout << reach(adj, x - 1, y - 1) << '\n'; }