#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
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) {
| ~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Unexpected end of file - int32 expected |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |