#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 2e5 + 10;
inline int read()
{
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int n, m;
bool vis[N];
vector<int> G[N];
inline void DFS(int u)
{
vis[u] = true;
for(re int to : G[u]) if(!vis[to]) DFS(to);
}
signed main()
{
n = read(), m = read();
if(m != n - 1) puts("No"), exit(0);
for(re int i = 1, x, y; i <= m; i++)
x = read(), y = read(), G[x].pb(y), G[y].pb(x);
DFS(1);
for(re int i = 1; i <= n; i++)
if(!vis[i]) puts("No"), exit(0); //不连通
for(re int i = 1; i <= n; i++)
if(G[i].size() > 2) puts("No"), exit(0);
int cnt = 0;
for(re int i = 1; i <= n; i++)
if(G[i].size() == 1) cnt += 1;
if(cnt != 2) puts("No"), exit(0);
puts("Yes");
return 0;
}
./Main.cpp: In function ‘void DFS(long long int)’:
./Main.cpp:29:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
29 | for(re int to : G[u]) if(!vis[to]) DFS(to);
| ^~
./Main.cpp: In function ‘int main()’:
./Main.cpp:35:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
35 | for(re int i = 1, x, y; i <= m; i++)
| ^
./Main.cpp:35:21: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
35 | for(re int i = 1, x, y; i <= m; i++)
| ^
./Main.cpp:35:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
35 | for(re int i = 1, x, y; i <= m; i++)
| ^
./Main.cpp:36:38: warning: address requested for ‘y’, which is declared ‘register’ [-Wextra]
36 | x = read(), y = read(), G[x].pb(y), G[y].pb(x);
| ^
./Main.cpp:36:50: warning: address requested for ‘x’, which is declared ‘register’ [-Wextra]
36 | x = read(), y = read(), G[x].pb(y), G[y].pb(x);
| ^
./Main.cpp:38:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
38 | for(re int i = 1; i <= n; i++)
| ^
./Main.cpp:40:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
40 | for(re int i = 1; i <= n; i++)
| ^
./Main.cpp:43:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
43 | for(re int i = 1; i <= n; i++)
| ^