arinado

Untitled

Jan 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <vector>
  4. #include<algorithm>
  5. #include<string>
  6. #include<math.h>
  7. #pragma comment(linker, "/STACK:66777216")
  8.  
  9. using namespace std;
  10.  
  11. #define ll unsigned _int64
  12. ll n, m;
  13. vector<ll>u;
  14. vector<vector<ll>>g;
  15.  
  16. void dfs(ll v) {
  17.     u[v] = 1;
  18.     for (ll to : g[v]) {
  19.         if (u[to] == 1) {
  20.             cout << "NO";
  21.             exit(0);
  22.         }
  23.         else if (!u[to]) dfs(to);
  24.     }
  25.     u[v] = 2;
  26. }
  27.  
  28. int main(void) {
  29.     ios_base::sync_with_stdio(false);
  30.     //  #ifndef ONLINE_JUDGE
  31.     freopen("input.txt", "r", stdin);
  32.     freopen("output.txt", "w", stdout);
  33.     //  #endif
  34.  
  35.     cin >> n >> m;
  36.     g.resize(n);
  37.     u.resize(n);
  38.     string s = "YES";
  39.     if (n - m != 1) s = "NO";
  40.     if (n == 1) {
  41.         cout << s;
  42.         exit(0);
  43.     }
  44.     for (ll i = 0; i < m; i++) {
  45.         ll a, b;
  46.         cin >> a >> b;
  47.         g[a - 1].push_back(b - 1);
  48.         g[b - 1].push_back(a - 1);
  49.     }
  50.     dfs(g[0][0]);
  51.     for (ll a : u) {
  52.         if (!a) {
  53.             cout << "NO";
  54.             exit(0);
  55.         }
  56.     }
  57.     cout << s;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment