SHARE
TWEET

Untitled

a guest Aug 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <utility>
  5. #include <set>
  6. #include <map>
  7. using namespace std;
  8.  
  9. vector<set<int>> v(2000);
  10. int was[2000];
  11.  
  12.  
  13. bool dfs(int x) {
  14.     was[x] = 1;
  15.     for (auto y : v[x]) {
  16.        
  17.         if (!was[y]) {
  18.             dfs(y);
  19.         }
  20.         else {
  21.             return 1;
  22.         }
  23.     }
  24.     return 0;
  25. }
  26.  
  27. int main() {
  28.    
  29.  
  30.     int n, m;
  31.     cin >> n >> m;
  32.  
  33.  
  34.     for (int i = 0; i < m; i++) {
  35.         int a, b;
  36.         cin >> a >> b;
  37.         v[a].insert(b);
  38.         v[b].insert(a);
  39.     }
  40.  
  41.     for (int i = 1; i <= n; i++) {
  42.         for (int i = 1; i <= n; i++) {
  43.             was[i] = 0;
  44.         }
  45.         if (dfs(i)) {
  46.             cout << "YES";
  47.             return 0;
  48.         }
  49.     }
  50.     cout << "NO";
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top