#include #include using namespace std; class BipartiteUnionFind { protected: vector root_of, size_of, unconnectables_of; vector color_of; size_t group; virtual size_t retrieve_true_root_of(const size_t index) { return root_of[index] == index ? index : retrieve_true_root_of(root_of[index]), color_of[index] = color_of[index] ^ color_of[root_of[index]], root_of[index] = root_of[root_of[index]]; } public: BipartiteUnionFind(const size_t N) : root_of(N), size_of(N, 1), unconnectables_of(N, 1), color_of(N, false), group(N) { for (size_t i = 0; i != N; ++i) root_of[i] = i; } virtual bool is_connected(const size_t a, const size_t b) { return retrieve_true_root_of(a) == retrieve_true_root_of(b); } virtual bool is_connectable(const size_t a, const size_t b) { return color_of[a] != color_of[b]; } virtual bool merge(const size_t a, const size_t b) { if (retrieve_true_root_of(a) != retrieve_true_root_of(b)) { unconnectables_of[root_of[a]] += color_of[a] ? count_unconnectables_of(b) : size_of[root_of[b]] - count_unconnectables_of(b); color_of[root_of[b]] = !(color_of[a] ^ color_of[b]), color_of[b] = !color_of[a]; size_of[root_of[a]] += size_of[root_of[b]]; root_of[b] = root_of[root_of[b]] = root_of[a]; --group; return true; } else return false; } size_t size_of_group_of(const size_t index) { return size_of[retrieve_true_root_of(index)]; } size_t groups() { return group; } size_t count_unconnectables_of(const size_t index) { return retrieve_true_root_of(index), color_of[index] ? size_of[root_of[index]] - unconnectables_of[root_of[index]] : unconnectables_of[root_of[index]]; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, a, b, i; cin >> n >> m; BipartiteUnionFind buf(n); for (i = 0; i != m; ++i) { cin >> a >> b, --a, --b; if (buf.is_connected(a, b)) { if (!buf.is_connectable(a, b)) { for (++i; i != m; ++i) cin >> a >> b; cout << "No\n"; return 0; } } else buf.merge(a, b); } cout << "Yes\n"; return 0; }