This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
vector<vector<ll>> adj;
bool cycle = false;
vector<bool> vis;
void search(int node, int prev = -1) {
vis[node] = true;
for (ll nei : adj[node]) {
if (nei == prev) continue;
if (vis[nei]) {
cycle = true;
break;
}
search(nei, node);
}
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
adj.resize(n);
for (int i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
vis.resize(n, false);
search(0);
if (cycle) {
cout << "NO\n";
} else {
cout << "YES\n";
cout << "1\n1\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |