Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<vector<int>> graf;
- vector<int> used;
- int k = 0;
- void dfs(int v) {
- k++;
- used[v] = 1;
- for (auto& el : graf[v]) {
- if (used[el] == 0) {
- dfs(el);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- int n, ans = 0;
- cin >> n;
- graf.resize(n);
- used.resize(n);
- for (auto& el : used) {
- el = 0;
- }
- for (int i = 0; i != n; i++) {
- for (int j = 0; j != n; j++) {
- int x;
- cin >> x;
- if (x == 1) {
- graf[i].push_back(j);
- ans++;
- }
- }
- }
- ans /= 2;
- dfs(0);
- if (k == n && ans==n-1) {
- cout << "YES";
- }
- else {
- cout << "NO";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement