-
Notifications
You must be signed in to change notification settings - Fork 0
/
PT07Y.cpp
47 lines (45 loc) · 888 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<bits/stdc++.h>
using namespace std;
using lld=long long int;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld n,m,k,a,b,ptr=0;
cin>>n>>m;
k=m;
vector <int> lst[n+1];
int vis[n+1]={0};
cin>>a>>b;
lst[a].push_back(b);
lst[b].push_back(a);
m--;
int start=a;
while(m--)
{
cin>>a>>b;
lst[a].push_back(b);
lst[b].push_back(a);
}
queue <int> q;
q.push(start);
vis[start]=1;
while(!q.empty())
{
a=q.front();
q.pop();
for(int i=0;i<lst[a].size();i++)
if(vis[lst[a][i]]==0)
{
vis[lst[a][i]]=1;
q.push(lst[a][i]);
}
}
for(int i=1;i<=n;i++)
if(vis[i]==0)
ptr=1;
if(n-k==1&&ptr==0)
cout<<"YES\n";
else
cout<<"NO\n";
}