Skip to content

Instantly share code, notes, and snippets.

@nafis00141
Created October 10, 2016 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nafis00141/854575e1b16c0e81ad289857cffb83a3 to your computer and use it in GitHub Desktop.
Save nafis00141/854575e1b16c0e81ad289857cffb83a3 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
vector<int>V[10005];
bool visited[10005];
void bfs(int a){
queue<int>Q;
visited[a]=true;
Q.push(a);
while(!Q.empty()){
int x = Q.front();
Q.pop();
for(int i=0;i<V[x].size();i++){
int d = V[x][i];
if(visited[d]==false){
visited[d]=true;
Q.push(d);
}
}
}
}
int main(){
memset(visited,false,sizeof(visited));
int n,e,a,b;
cin>>n>>e;
for(int i=0;i<e;i++){
cin>>a>>b;
V[a].push_back(b);
V[b].push_back(a);
}
if(n==(e+1)){
bfs(1);
for(int i=1;i<=n;i++){
if(visited[i]==false){
printf("NO\n");
return 0;
}
}
printf("YES\n");
}
else{
printf("NO\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment