Advertisement
9I_HE_TbI_A_9I

Untitled

Aug 29th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. vector<vector<int>> graf;
  8. vector<int> used;
  9. int k = 0;
  10.  
  11. void dfs(int v) {
  12.     k++;
  13.     used[v] = 1;
  14.     for (auto& el : graf[v]) {
  15.         if (used[el] == 0) {
  16.             dfs(el);
  17.         }
  18.     }
  19. }
  20.  
  21. int main()
  22. {
  23.     ios::sync_with_stdio(false);
  24.     int n, ans = 0;
  25.     cin >> n;
  26.     graf.resize(n);
  27.     used.resize(n);
  28.     for (auto& el : used) {
  29.         el = 0;
  30.     }
  31.     for (int i = 0; i != n; i++) {
  32.         for (int j = 0; j != n; j++) {
  33.             int x;
  34.             cin >> x;
  35.             if (x == 1) {
  36.                 graf[i].push_back(j);
  37.                 ans++;
  38.             }
  39.         }
  40.     }
  41.     ans /= 2;
  42.     dfs(0);
  43.     if (k == n && ans==n-1) {
  44.         cout << "YES";
  45.     }
  46.     else {
  47.         cout << "NO";
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement