#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
const int N = 1007;
int n, m;
vector<int> adj[N], cur;
int leaf[N];
void dfs(int v) {
int t = -1;
for (int u : adj[v]) {
if (leaf[u])
leaf[u] = 0;
else {
if (t == -1)
t = u;
else {
t = -2;
break;
}
}
}
cur.push_back(v);
leaf[v] = 1;
if (t > 0)
dfs(t);
}
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if (m != n - 1) {
cout << "NO" << '\n';
return 0;
}
vector<int> ans;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
leaf[j] = adj[j].size() == 1;
cur.clear();
dfs(i);
if (accumulate(leaf + 1, leaf + n + 1, 0) == 1) {
for (int j = 1; j <= n; j++)
if (leaf[j] == 1)
cur.push_back(j);
if (ans.empty() || cur.size() < ans.size())
ans = cur;
}
}
if (ans.empty())
cout << "NO" << '\n';
else {
cout << "YES" << '\n' << ans.size() << '\n';
for (int x : ans)
cout << x << ' ';
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
0 ms |
480 KB |
Failed to provide a successful strategy. |
5 |
Correct |
0 ms |
480 KB |
Output is correct |
6 |
Partially correct |
0 ms |
488 KB |
Failed to provide a successful strategy. |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Partially correct |
1 ms |
348 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
6 |
Partially correct |
1 ms |
600 KB |
Failed to provide a successful strategy. |
7 |
Partially correct |
1 ms |
348 KB |
Failed to provide a successful strategy. |
8 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
9 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
10 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
11 |
Partially correct |
2 ms |
348 KB |
Failed to provide a successful strategy. |
12 |
Partially correct |
2 ms |
348 KB |
Failed to provide a successful strategy. |
13 |
Partially correct |
1 ms |
348 KB |
Failed to provide a successful strategy. |
14 |
Partially correct |
1 ms |
348 KB |
Failed to provide a successful strategy. |
15 |
Partially correct |
1 ms |
348 KB |
Failed to provide a successful strategy. |
16 |
Partially correct |
2 ms |
348 KB |
Failed to provide a successful strategy. |
17 |
Partially correct |
2 ms |
348 KB |
Failed to provide a successful strategy. |
18 |
Partially correct |
2 ms |
348 KB |
Failed to provide a successful strategy. |
19 |
Partially correct |
4 ms |
604 KB |
Failed to provide a successful strategy. |
20 |
Partially correct |
2 ms |
348 KB |
Failed to provide a successful strategy. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
0 ms |
480 KB |
Failed to provide a successful strategy. |
5 |
Correct |
0 ms |
480 KB |
Output is correct |
6 |
Partially correct |
0 ms |
488 KB |
Failed to provide a successful strategy. |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |