#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
vector <int> adj[maxn];
bool mark[maxn];
int par[maxn];
bool cycle = false;
void dfs(int u){
mark[u] = true;
for(auto v: adj[u]){
if(!mark[v]){
par[v] = u;
dfs(v);
}
else{
if(v != par[u]){
cycle = true;
}
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, m; cin >> n >> m;
for(int i = 0; i < m; i ++){
int u, v;
cin >> u >> v;
u --; v --;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0);
if(cycle){
cout << "NO";
}
else{
cout << "YES";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |