Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define close_all { \
- out.close(); \
- in.close(); }
- using namespace std;
- #define int long long
- int n;
- map<int, vector<int>> graph;
- map<int, bool> used;
- set<int> curr;
- map<int, bool> root;
- bool chk;
- void dfs(int v) {
- used[v] = true;
- curr.insert(v);
- for (auto dest : graph[v]) {
- if (!used[dest]) {
- dfs(dest);
- }
- }
- }
- signed main() {
- int m;
- cin >> n >> m;
- if (m != n - 1) {
- chk = true;
- }
- set<int> c;
- for (int i = 0; i < m; ++i) {
- int a, b;
- cin >> a >> b;
- graph[a - 1].push_back(b - 1);
- graph[b - 1].push_back(a - 1);
- }
- dfs(0);
- if (curr.size() != n) {
- chk = true;
- }
- if (chk) {
- cout << "no";
- } else {
- cout << "yes";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment