-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPT07Y.cpp
47 lines (47 loc) · 819 Bytes
/
PT07Y.cpp
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
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
int t=n;
vector<vector<int>> v(m+1);
for(int i=1;i<m+1;++i)
v[i].push_back(i);
while(t--){
int i,j;
cin>>i>>j;
v[i].push_back(j);
v[j].push_back(i);
}
if(m-1!=n){
cout<<"\nNO\n";
return 0;
}
bool visited[m+1];
for(int i=1;i<m+1;++i)
visited[i]=false;
stack<int> mys;
mys.push(v[1][0]);
while(mys.empty()==false){
int s=mys.top();
mys.pop();
if(visited[s]==false){
visited[s]=true;
for(int i=0;i<v[s].size();++i){
if(visited[v[s][i]]==false){
mys.push(v[s][i]);
}
}
}
}
for(int i=1;i<m+1;++i){
if(visited[i]==false){
cout<<"\nNO\n";
return 0;
}
}
cout<<"\nYES\n";
return 0;
}