You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
688 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = N << 2;
int e[M], h[N], idx, w[M], ne[M];
void add(int a, int b, int c = 0) {
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
}
int n, m;
bool st[N];
int cnt;
void dfs(int u) {
st[u] = 1;
cnt++;
for (int i = h[u]; ~i; i = ne[i]) {
int v = e[i];
if (!st[v]) dfs(v);
}
}
int main() {
memset(h, -1, sizeof h);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
add(a, b);
}
dfs(1);
if (cnt == n)
printf("Yes\n");
else
printf("No\n");
return 0;
}