Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include "stdio.h"
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <set>
- using namespace std;
- void dfs(int &v, vector<vector<int>> &a, vector<bool> &used, int &cnt)
- {
- used[v] = true;
- cnt++;
- for (int i = 0; i < a[v].size(); ++i)
- if (!used[a[v][i]])
- dfs(a[v][i], a, used, cnt);
- }
- void main()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, m, cnt, flag = 1;
- cin >> n >> m;
- vector<vector<int>> a (n);
- vector<bool> used(n);
- for (int i = 0; i < m; ++i)
- {
- int ch, ch1;
- ch--, ch1--;
- a[ch].push_back(ch1);
- a[ch1].push_back(ch);
- }
- for (int i = 0; i < n; ++i)
- if (!used[i])
- {
- dfs(i, a, used, cnt = -1);
- if (a[i].size() == cnt)
- flag *= 1;
- else
- flag *= 0;
- }
- if (flag == 1)
- cout << "YES";
- else
- cout << "NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement