Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include<algorithm>
- #include<string>
- #include<math.h>
- #pragma comment(linker, "/STACK:66777216")
- using namespace std;
- #define ll unsigned _int64
- ll n, m;
- vector<ll>u;
- vector<vector<ll>>g;
- void dfs(ll v) {
- u[v] = 1;
- for (ll to : g[v]) {
- if (u[to] == 1) {
- cout << "NO";
- exit(0);
- }
- else if (!u[to]) dfs(to);
- }
- u[v] = 2;
- }
- int main(void) {
- ios_base::sync_with_stdio(false);
- // #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- // #endif
- cin >> n >> m;
- g.resize(n);
- u.resize(n);
- string s = "YES";
- if (n - m != 1) s = "NO";
- if (n == 1) {
- cout << s;
- exit(0);
- }
- for (ll i = 0; i < m; i++) {
- ll a, b;
- cin >> a >> b;
- g[a - 1].push_back(b - 1);
- g[b - 1].push_back(a - 1);
- }
- dfs(g[0][0]);
- for (ll a : u) {
- if (!a) {
- cout << "NO";
- exit(0);
- }
- }
- cout << s;
- }
Advertisement
Add Comment
Please, Sign In to add comment