LONELINESS WILL SHINE
Too hard。
从菊花入手,容易发现菊花的根取
考虑一般情况,沿用上面的做法,钦定
代码很短。
#include <bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
const int N = 100;
vector<pair<int, int> > G[N];
int n, res[N];
void DFS(int u, int f, int s) {
res[u] = s;
for (auto [v, x] : G[u]) if (v != f) DFS(v, u, s ^ (1 << x));
}
int main() {
freopen(".in", "r", stdin); freopen(".out", "w", stdout);
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0, u, v; i < n; i ++)
cin >> u >> v, G[u].push_back({v, i}), G[v].push_back({u, i});
cout << (1 << (n - 1)) << "\n";
for (int s = 0; s < (1 << n); s ++) if (__builtin_popcount(s) % 2 == 0) {
DFS(0, 0, s);
for (int i = 0; i <= n; i ++) cout << res[i] << " \n"[i == n];
}
return 0;
}