#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, d[maxn], pre[maxn];
vector<int> path, ans, G[maxn];
int main() {
scanf("%d %d", &n, &m);
if (m >= n) puts("NO"), exit(0);
while (m--) {
int u, v;
scanf("%d %d", &u, &v);
G[u].push_back(v), G[v].push_back(u);
}
auto bfs = [&]() {
queue<int> Q;
for (int i = 1; i <= n; i++) {
if (!d[i]) Q.push(i);
}
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (int v : G[u]) if (!~d[v]) {
Q.push(v), d[v] = d[u] + 1, pre[v] = u;
}
}
};
memset(d, -1, sizeof(d));
d[1] = 0, bfs();
int s = max_element(d + 1, d + n + 1) - d;
memset(d, -1, sizeof(d));
d[s] = 0, bfs();
int t = max_element(d + 1, d + n + 1) - d;
for (int i = t; i ^ s; i = pre[i]) path.push_back(i);
path.push_back(s);
memset(d, -1, sizeof(d));
for (int i : path) d[i] = 0;
bfs();
if (*max_element(d + 1, d + n + 1) > 2) puts("NO"), exit(0);
for (int i = 0; i < path.size(); i++) {
ans.push_back(path[i]), ans.push_back(path[i]);
for (int j : G[i]) if (d[j] == 1) {
bool flag = 0;
for (int k : G[j]) flag |= d[k] == 2;
if (flag) ans.push_back(path[j]), ans.push_back(path[i]);
}
}
printf("YES\n%d\n", ans.size());
for (int x : ans) printf("%d ", x);
return 0;
}
Compilation message
newspapers.cpp: In function 'int main()':
newspapers.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < path.size(); i++) {
| ~~^~~~~~~~~~~~~
newspapers.cpp:48:19: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
48 | printf("YES\n%d\n", ans.size());
| ~^ ~~~~~~~~~~
| | |
| int std::vector<int>::size_type {aka long unsigned int}
| %ld
newspapers.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
newspapers.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d %d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
2 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
3 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Incorrect |
1 ms |
332 KB |
Integer 0 violates the range [1, 7] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
2 |
Partially correct |
0 ms |
204 KB |
Provide a successful but not optimal strategy. |
3 |
Partially correct |
1 ms |
316 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
6 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
7 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
8 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
9 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
10 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
11 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
12 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
13 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
14 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
15 |
Partially correct |
1 ms |
324 KB |
Failed to provide a successful strategy. |
16 |
Partially correct |
1 ms |
324 KB |
Failed to provide a successful strategy. |
17 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
18 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
19 |
Partially correct |
2 ms |
332 KB |
Failed to provide a successful strategy. |
20 |
Partially correct |
1 ms |
332 KB |
Failed to provide a successful strategy. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
2 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
3 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
1 ms |
204 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
1 ms |
204 KB |
Failed to provide a successful strategy. |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Incorrect |
1 ms |
332 KB |
Integer 0 violates the range [1, 7] |
9 |
Halted |
0 ms |
0 KB |
- |