//#include #include #include #include using std::vector; using std::queue; bool bfsBipartiteCheck(vector> &adj, int s) { if (adj[s].size() == 0) return true; vector dist(adj.size(), -1); dist[s] = 0; queue vertexQ; vertexQ.push(s); while (!vertexQ.empty()) { int u = vertexQ.front(); vertexQ.pop(); for (int i : adj[u]) { if (dist[i] == -1) { vertexQ.push(i); if (dist[u] == 0) dist[i] = 1; if (dist[u] == 1) dist[i] = 0; } else if (dist[i] == dist[u]) return false; } } return true; } int bipartite(vector > &adj) { bool bipartiteCheckNodes = bfsBipartiteCheck(adj, 0); if (bipartiteCheckNodes) return 1; else return 0; } int main() { int n, m; std::cin >> n >> m; vector > adj(n, vector()); for (int 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); } std::cout << bipartite(adj); } //TEST(Acyclicity, ac1) { // vector> adj = { { 1 }, { 2 }, { 0 }, { 0 } }; // ASSERT_EQ(acyclic(adj), 1); //}