// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
int n, m;
vi ans, graph[1001];
int parity[1001], cnt[1001];
bitset<1001> removed;
void dfs(int u, int p, int c) {
if (parity[u] != -1) {
cout << "NO" << endl;
exit(0);
}
parity[u] = c;
trav(v, graph[u]) if (v != p) dfs(v, u, c ^ 1);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
memset(parity, -1, sizeof(parity));
cin >> n >> m;
rep(i, 0, m) {
int u, v;
cin >> u >> v;
graph[--u].pb(--v);
graph[v].pb(u);
}
dfs(0, 0, 0);
bool moves = 0;
while (1) {
if (sz(ans) > 5 * n) break;
int need = 0, node;
bool stop=1;
memset(cnt, 0, sizeof(cnt));
rep(u, 0, n) if (moves == parity[u] && !removed[u]) {
stop=0;
bool adj_rem = 0;
trav(v, graph[u]) {
++cnt[v];
if (removed[v]) adj_rem = 1;
}
need += adj_rem;
if (need) node = u;
}
if(stop)break;
if (need > 1) {
cout << "NO" << endl;
return 0;
}
if (!need) {
int mx_rem = -1;
rep(u, 0, n) if (moves == parity[u] && !removed[u]) {
int cur_rem = 0;
trav(v, graph[u]) if (cnt[v] == 1)++ cur_rem;
if (cur_rem > mx_rem) {
mx_rem = cur_rem;
node = u;
}
}
}
//cout<<"moves = "<<moves<<" node = "<<node<<endl;
ans.pb(node);
trav(v, graph[node])-- cnt[v];
moves ^= 1;
rep(u, 0, n) if (parity[u] == moves && !cnt[u]) removed[u] = 1;
}
if (sz(ans) > 5 * n)
cout << "NO" << endl;
else {
cout << "YES\n"
<< 2 * sz(ans) + 1 - moves<<endl;
trav(pos,ans)cout<<pos+1<<' ';
if(!moves)cout<<"1 ";
trav(pos,ans)cout<<pos+1<<' ';
cout<<endl;
}
return 0;
}
Compilation message
newspapers.cpp: In function 'int main()':
newspapers.cpp:63:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
63 | if (sz(ans) > 5 * n) break;
| ^
newspapers.cpp:105:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
105 | if (sz(ans) > 5 * n)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Partially correct |
0 ms |
332 KB |
Failed to provide a successful strategy. |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
0 ms |
344 KB |
Failed to provide a successful strategy. |
7 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
8 |
Partially correct |
0 ms |
340 KB |
Failed to provide a successful strategy. |
9 |
Partially correct |
1 ms |
332 KB |
Provide a successful but not optimal strategy. |
10 |
Partially correct |
0 ms |
332 KB |
Failed to provide a successful strategy. |
11 |
Partially correct |
6 ms |
332 KB |
Failed to provide a successful strategy. |
12 |
Partially correct |
2 ms |
332 KB |
Provide a successful but not optimal strategy. |
13 |
Partially correct |
3 ms |
332 KB |
Failed to provide a successful strategy. |
14 |
Partially correct |
3 ms |
332 KB |
Failed to provide a successful strategy. |
15 |
Partially correct |
3 ms |
344 KB |
Provide a successful but not optimal strategy. |
16 |
Partially correct |
7 ms |
332 KB |
Failed to provide a successful strategy. |
17 |
Partially correct |
5 ms |
332 KB |
Provide a successful but not optimal strategy. |
18 |
Partially correct |
6 ms |
460 KB |
Failed to provide a successful strategy. |
19 |
Partially correct |
5 ms |
332 KB |
Provide a successful but not optimal strategy. |
20 |
Partially correct |
7 ms |
440 KB |
Failed to provide a successful strategy. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
0 ms |
348 KB |
Failed to provide a successful strategy. |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Partially correct |
0 ms |
332 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Partially correct |
0 ms |
332 KB |
Failed to provide a successful strategy. |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |