| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n, m;
- cin >> n >> m;
- vector<vector<int>> graph(n);
- vector<int> degree(n, 0);
- for (int i = 0; i < m; ++i) {
- int u, v;
- cin >> u >> v;
- --u;
- --v;
- graph[u].push_back(v);
- graph[v].push_back(u);
- ++degree[u];
- ++degree[v];
- }
- for (int d : degree) {
- if (d & 1) {
- cout << "No\n";
- return 0;
- }
- }
- for (int d : degree) {
- if (d >= 6) {
- cout << "Yes\n";
- return 0;
- }
- }
- vector<int> four;
- for (int v = 0; v < n; ++v) {
- if (degree[v] == 4) four.push_back(v);
- }
- if (four.size() >= 3) {
- cout << "Yes\n";
- return 0;
- }
- if (four.size() <= 1) {
- cout << "No\n";
- return 0;
- }
- const int start = four[0], forbidden = four[1];
- vector<char> visited(n, false);
- stack<pair<int, int>> work;
- for (int to : graph[start]) {
- if (to != forbidden) work.push({to, start});
- }
- visited[start] = true;
- bool found_cycle_avoiding_other = false;
- while (!work.empty()) {
- auto [v, parent] = work.top();
- work.pop();
- if (v == start) {
- found_cycle_avoiding_other = true;
- break;
- }
- if (v == forbidden || visited[v]) continue;
- visited[v] = true;
- for (int to : graph[v]) {
- if (to != parent) work.push({to, v});
- }
- }
- cout << (found_cycle_avoiding_other ? "Yes\n" : "No\n");
- return 0;
- }
|