-
Notifications
You must be signed in to change notification settings - Fork 185
/
b.cc
49 lines (47 loc) · 1.01 KB
/
b.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// https://codeforces.com/contest/1169/problem/B
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ii = tuple<int, int>;
using vii = vector<ii>;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, p, q, u, v;
cin >> n >> m;
vii a(m);
for (int i = 0; i < m; i++) {
cin >> u >> v;
a[i] = { u, v };
}
bool ok = true;
vii b;
tie(p, q) = a[0];
for (int i = 1; i < m; i++) {
tie(u, v) = a[i];
if (p != u && q != u && p != v && q != v) {
b.push_back({p, u});
b.push_back({p, v});
b.push_back({q, u});
b.push_back({q, v});
break;
}
}
if (!b.empty())
for (int i = 0; i < m; i++) {
tie (u, v) = a[i];
int j = 0;
while (j < b.size()) {
tie(p, q) = b[j];
if (u != p && u != q && v != p && v != q) {
swap(b[j], b.back());
b.pop_back();
} else j++;
}
if (b.empty()) {
ok = false;
break;
}
}
cout << (ok ? "YES\n" : "NO\n");
}