#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e3 + 10;
int n, m, dist[MAXN], par[MAXN], D[MAXN];
vector<int> adj[MAXN], diam, ans;
void dfs(int v) {
dist[v] = dist[par[v]] + 1;
D[v] = 1;
for (int u : adj[v]) {
if (u != par[v]) {
par[u] = v;
dfs(u);
D[v] = max(D[v], D[u] + 1);
}
}
}
inline void dojob() {
int m = diam.size();
int i = 0;
for (i = 0; i < m - 1; i++) {
int v = diam[i];
if (i & 1) ans.push_back(v);
for (int u : adj[v]) {
if (u == par[v] || u == diam[i + 1]) continue;
if (D[u] >= 3) {
cout << "NO" << endl;
exit(0);
}
ans.push_back(v);
ans.push_back(u);
}
ans.push_back(v);
ans.push_back(diam[i + 1]);
}
if (i == m - 1) ans.push_back(diam[i]);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
if (m >= n) return cout << "NO" << endl, 0;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1);
int v = max_element(dist, dist + MAXN) - dist;
dfs(v);
v = max_element(dist, dist + MAXN) - dist;
while (v) {
diam.push_back(v);
v = par[v];
}
reverse(all(diam));
dojob();
if (ans.size() % 2 == 0) ans.push_back(1);
dojob();
cout << "YES" << endl << ans.size() << endl;
for (int e : ans) cout << e << sep;
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
602 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
602 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
602 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |