Advertisement
Guest User

D2B O(m) solution

a guest
May 23rd, 2019
9,908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. #ifdef ONPC
  8.   mt19937 rnd(228);
  9. #else
  10.   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
  11. #endif
  12.  
  13. int main() {
  14. #ifdef ONPC
  15.   freopen("a.in", "r", stdin);
  16. #endif
  17.   ios::sync_with_stdio(0);
  18.   cin.tie(0);
  19.   int n, m;
  20.   cin >> n >> m;
  21.   vector <pair <int, int> > pairs;
  22.   for (int i = 0; i < m; i++) {
  23.     int a, b;
  24.     cin >> a >> b;
  25.     a--, b--;
  26.     pairs.emplace_back(a, b);
  27.   }
  28.   vector <int> values = {pairs[0].first, pairs[0].second};
  29.   for (int x : values) {
  30.     vector <int> val(n);
  31.     int all = 0;
  32.     for (auto c : pairs) {
  33.       if (c.first != x && c.second != x) {
  34.         val[c.first]++, val[c.second]++, all++;
  35.       }
  36.     }
  37.     if (*max_element(val.begin(), val.end()) == all) {
  38.       cout << "YES\n";
  39.       return 0;
  40.     }
  41.   }
  42.   cout << "NO\n";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement