#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int N, M;
vvi adj;
vvi adj2;
bool possible;
vi cnt[2];
vvi CNT[2];
vi ans;
vi bw;
vi BW[2];
void dfsBW(int v, int p)
{
bw[v] = !bw[p];
BW[bw[v]].push_back(v);
for (int u : adj[v])
if (u != p)
dfsBW(u, v);
}
void dfs(int v, int p)
{
cnt[0][v] = 1;
cnt[1][v] = 0;
for (int u : adj[v])
if (u != p)
{
dfs(u, v);
cnt[0][v] += cnt[1][u];
cnt[1][v] += cnt[0][u];
}
}
void dfsAns(int v, int p)
{
ans.push_back(v); // safe besuchen
vi todo;
for (int u : adj2[v])
if (u != p)
todo.push_back(u);
dfs(v, v);
if (sz(todo) <= 1)
{
for (int u : adj[v])
if (u != p && (todo.empty() || u != todo[0]) && cnt[1][u] > 0)
{
assert(cnt[0][u] == 1);
ans.push_back(u);
ans.push_back(v);
}
if (sz(todo) == 1)
{
dfsAns(todo[0], v);
}
}
else
{
// must be 2
assert(false);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
if (M > N - 1)
{
cout << "NO\n";
return 0;
}
adj.resize(N);
for (int i = 0, a, b; i < M; ++i)
{
cin >> a >> b;
--a, --b;
adj[a].push_back(b), adj[b].push_back(a);
}
bw.assign(N, 0);
dfsBW(0, 0);
adj2.resize(N);
possible = true;
cnt[0].resize(N), cnt[1].resize(N);
for (int v = 0; v < N; ++v)
{
dfs(v, v);
for (int u : adj[v])
if (cnt[0][u] >= 2)
adj2[v].push_back(u);
if (sz(adj2[v]) > 2)
possible = false;
}
if (possible)
{
cout << "YES\n";
int color = 0;
if (sz(BW[!color]) < sz(BW[color]))
color = !color;
if (BW[color].empty())
{
ans.push_back(0);
}
else
{
int start = BW[color].front();
for (int v : BW[color])
{
if (sz(adj2[v]) == 1)
start = v;
}
dfsAns(start, start);
int n = sz(ans);
for (int i = n - 1; i >= 0; --i)
ans.push_back(ans[i]);
}
cout << sz(ans) << '\n';
for (int x : ans)
cout << x + 1 << " ";
cout << '\n';
}
else
cout << "NO\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
7 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
8 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
9 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
10 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
11 |
Partially correct |
14 ms |
596 KB |
Provide a successful but not optimal strategy. |
12 |
Partially correct |
5 ms |
484 KB |
Provide a successful but not optimal strategy. |
13 |
Partially correct |
6 ms |
452 KB |
Provide a successful but not optimal strategy. |
14 |
Partially correct |
7 ms |
508 KB |
Provide a successful but not optimal strategy. |
15 |
Partially correct |
8 ms |
468 KB |
Provide a successful but not optimal strategy. |
16 |
Partially correct |
16 ms |
576 KB |
Provide a successful but not optimal strategy. |
17 |
Partially correct |
16 ms |
596 KB |
Provide a successful but not optimal strategy. |
18 |
Partially correct |
16 ms |
596 KB |
Provide a successful but not optimal strategy. |
19 |
Partially correct |
16 ms |
672 KB |
Provide a successful but not optimal strategy. |
20 |
Partially correct |
17 ms |
636 KB |
Provide a successful but not optimal strategy. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
1 ms |
212 KB |
Provide a successful but not optimal strategy. |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |