#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 1010;
int n, m;
void solve_chain()
{
if (n == 1)
{
cout << "YES" << endl;
cout << 1 << endl;
cout << 1 << endl;
return;
}
cout << "YES" << endl;
if (n % 2 == 1)
{
cout << 2 * n << endl;
for (int i = 1; i <= n; i ++)
cout << i << " ";
for (int i = 1; i <= n; i ++)
cout << i << " ";
cout << endl;
}
else
{
cout << 2 * n + 1<< endl;
for (int i = 1; i <= n; i ++)
cout << i << " ";
cout << 1 << " ";
for (int i = 1; i <= n; i ++)
cout << i << " ";
cout << endl;
}
}
vector < int > adj[maxn];
const int maxmask = (1 << 21);
int dp[maxmask], from[maxn], last[maxn];
int transition_mask(int mask, int ver)
{
int new_mask = 0;
if ((mask & (1 << (ver - 1))) > 0)
mask -= (1 << (ver - 1));
for (int v = 1; v <= n; v ++)
{
if ((mask & (1 << (v - 1))) == 0)
continue;
for (int u : adj[v])
new_mask |= (1 << (u - 1));
}
return new_mask;
}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= m; i ++)
{
int v, u;
cin >> v >> u;
adj[v].push_back(u);
adj[u].push_back(v);
}
if (n > 20)
{
solve_chain();
return;
}
int base_mask = (1 << n) - 1;
for (int mask = 0; mask < (1 << n); mask ++)
dp[mask] = -1;
dp[base_mask] = 0;
queue < int > q;
q.push(base_mask);
while(!q.empty())
{
int mask = q.front();
q.pop();
for (int i = 0; i < n; i ++)
{
int next_mask = transition_mask(mask, i + 1);
if (dp[next_mask] == -1)
{
dp[next_mask] = dp[mask] + 1;
from[next_mask] = i + 1;
last[next_mask] = mask;
q.push(next_mask);
}
}
}
if (dp[0] == -1)
{
cout << "No" << endl;
return;
}
vector < int > ord;
int cur = 0;
while(cur != base_mask)
{
ord.push_back(from[cur]);
cur = last[cur];
}
reverse(ord.begin(), ord.end());
cout << "YES" << endl;
cout << ord.size() << endl;
for (int cur : ord)
cout << cur << " ";
cout << endl;
}
int main()
{
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
Token "No" doesn't correspond to pattern "YES|NO" |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Runtime error |
238 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
Token "No" doesn't correspond to pattern "YES|NO" |
8 |
Halted |
0 ms |
0 KB |
- |