-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpt07y.cpp
More file actions
38 lines (34 loc) · 749 Bytes
/
pt07y.cpp
File metadata and controls
38 lines (34 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <vector>
using namespace std;
bool flagged = false;
bool visited[10000];
vector <int> connected[10000];
void dfs(int src) {
visited[src] = true;
for (int i = 0; i < connected[src].size(); ++i)
if (!visited[connected[src][i]])
dfs(connected[src][i]);
}
int main() {
freopen("input.txt", "r", stdin);
int nodes, edges, a, b;
cin >> nodes >> edges;
for (int i = 0; i < nodes; ++i)
visited[i] = false;
if (edges != nodes-1)
flagged = true;
while (edges--) {
cin >> a >> b;
connected[a-1].push_back(b-1);
connected[b-1].push_back(a-1);
}
dfs(0);
for (int i = 0; i < nodes; ++i)
if (!visited[i])
flagged = true;
if (flagged)
cout << "NO" << endl;
else cout << "YES" << endl;
return 0;
}