-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpt07y.cpp
More file actions
48 lines (47 loc) · 901 Bytes
/
pt07y.cpp
File metadata and controls
48 lines (47 loc) · 901 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
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
bool visited[10002];
bool dfs(vector<int>* adj,int u,int parent) {
visited[u]=true;
for(int i=0;i<adj[u].size();i++) {
int v=adj[u][i];
if(!visited[v]) {
if(dfs(adj,v,u))
return true;
} else if(v!=parent)
return true;
}
return false;
}
bool isCycle(vector<int>* adj,int n) {
for(int i=1;i<=n;i++) {
if(!visited[i])
if(dfs(adj,i,-1))
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
vector<int>* adj=new vector<int>[n+2];
for(int i=0;i<m;i++) {
int x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
if(isCycle(adj,n))
cout<<"NO\n";
else
cout<<"YES\n";
return 0;
}