#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 20;
int n, m, dist[1 << MAXN], t[1 << MAXN];
vector<int> adj[MAXN];
vector<pll> badj[1 << MAXN];
inline int f(int mask, int v) {
mask = (mask | (1 << v)) ^ (1 << v);
vector<int> vec;
int ans = 0;
for (int i = 0; i < n; i++)
if (mask & (1 << i))
for (int u : adj[i])
ans |= (1 << u);
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
if (m >= n) return cout << "NO" << endl, 0;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u - 1].push_back(v - 1);
adj[v - 1].push_back(u - 1);
}
for (int mask = 1; mask < (1 << n); mask++)
for (int i = 0; i < n; i++)
badj[f(mask, i)].push_back({mask, i});
memset(dist, 63, sizeof dist);
queue<int> q;
dist[0] = 0;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto [u, x] : badj[v]) {
if (dist[u] > dist[v] + 1) {
dist[u] = dist[v] + 1;
t[u] = x;
q.push(u);
}
}
}
int mask = (1 << n) - 1;
if (dist[mask] > MAXN * MAXN) return cout << "NO" << endl, 0;
cout << dist[mask] << endl;
while (mask) {
cout << t[mask] + 1 << sep;
mask = f(mask, t[mask]);
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
29048 KB |
Token "1" doesn't correspond to pattern "YES|NO" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
29012 KB |
Token "1" doesn't correspond to pattern "YES|NO" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
29048 KB |
Token "1" doesn't correspond to pattern "YES|NO" |
2 |
Halted |
0 ms |
0 KB |
- |