#include #include #include using namespace std; template struct Graph { public: using value_type = T; struct Edge { int from, to; T cost; int id; operator int() const { return to; } }; Graph() {} Graph(int n) : n(n), m(0), g(n) {} void add_directed_edge(int from, int to, T cost = 1) { assert(0 <= from && from < n); assert(0 <= to && to < n); g[from].push_back((Edge){from, to, cost, m++}); } void add_undirected_edge(int from, int to, T cost = 1) { assert(0 <= from && from < n); assert(0 <= to && to < n); g[from].push_back((Edge){from, to, cost, m}); g[to].push_back((Edge){to, from, cost, m++}); } int size() { return n; } int edge_size() { return m; } inline const std::vector &operator[](const int &u) const { return g[u]; } inline std::vector &operator[](const int &u) { return g[u]; } private: int n, m; std::vector> g; }; std::vector is_bipartite(Graph &g) // b[n] == 1 <=> g is bipartite { int n = g.size(); std::vector b(n + 1, -1); b[n] = 0; std::queue que; for (int i = 0; i < n; i++) { if (b[i] != -1) { continue; } b[i] = 0; que.push(i); while (que.size()) { int u = que.front(); que.pop(); for (int v : g[u]) { if (b[u] == b[v]) { return b; } if (b[v] == -1) { b[v] = 1 - b[u]; que.push(v); } } } } b[n] = 1; return b; } int main() { int n, m; cin >> n >> m; Graph g(n); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; g.add_undirected_edge(a, b); } vector b = is_bipartite(g); if(b[n]) { cout << "Yes" << endl; } else { cout << "No" << endl; } }