# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
928853 | math_rabbit_1028 | Newspapers (CEOI21_newspapers) | C++14 | 1 ms | 488 KiB |
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;
int N, M;
vector<int> adj[1010];
int ch[1010], par[1010], dia[1010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for (int i = 1; i <= M; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
if (M >= N) {
cout << "NO\n";
return 0;
}
queue<int> q;
int r, s;
for (int i = 1; i <= N; i++) ch[i] = 0;
q.push(1);
while (!q.empty()) {
int v = q.front();
r = v;
q.pop();
ch[v] = 1;
for (int u : adj[v]) {
if (ch[u]) continue;
q.push(u);
}
}
par[r] = 0;
for (int i = 1; i <= N; i++) ch[i] = 0;
q.push(r);
while (!q.empty()) {
int v = q.front();
s = v;
q.pop();
ch[v] = 1;
for (int u : adj[v]) {
if (ch[u]) continue;
par[u] = v;
q.push(u);
}
}
// cout << r << " " << s << "\n";
while (s > 0) {
dia[s] = 1;
s = par[s];
}
for (int i = 1; i <= N; i++) {
if (dia[i]) continue;
for (int v : adj[i]) {
if (dia[v]) continue;
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
if (N == 1) cout << "1\n1\n";
else if (N == 2) cout << "2\n1 1\n";
else {
cout << 2*N-4 << "\n";
for (int i = 2; i <= N-1; i++) cout << i << " ";
for (int i = N-1; i >= 2; i--) cout << i << " ";
cout << "\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |