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 i64 = long long;
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
constexpr int max_N = int(1000) + 5;
int N, M;
std::vector<int> adj[max_N], cdj[max_N];
std::vector<int> stk;
int tin[max_N], low[max_N], belong[max_N], siz[max_N], timer, nc;
void dfs1(int v, int pr) {
stk.emplace_back(v);
low[v] = tin[v] = ++timer;
for (auto u : adj[v]) {
if (u == pr) {
continue;
}
if (low[u] == 0) {
dfs1(u, v);
low[v] = std::min(low[v], low[u]);
} else if (belong[u] == 0) {
low[v] = std::min(low[v], tin[u]);
}
}
if (low[v] == tin[v]) {
++nc;
int u;
do {
u = stk.back();
stk.pop_back();
belong[u] = nc;
++siz[nc - 1];
} while (u != v);
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> N >> M;
for (int i = 0; i < M; ++i) {
int A, B;
std::cin >> A >> B;
--A, --B;
adj[A].emplace_back(B);
adj[B].emplace_back(A);
}
dfs1(0, 0);
if (nc != N) {
std::cout << "NO\n";
return 0;
}
for (int i = 0; i < N; ++i) {
if (adj[i].size() == M) {
std::cout << "YES\n";
std::cout << "2\n";
std::cout << i + 1 << ' ' << i + 1 << '\n';
return 0;
}
}
std::cout << "YES\n";
return 0;
}
Compilation message (stderr)
newspapers.cpp: In function 'int main()':
newspapers.cpp:65:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
65 | if (adj[i].size() == M) {
| ~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |