#include <iostream>
#include <vector>
using namespace std;
int pop_cnt(int x) {
int ans = 0;
while (x > 0) {
ans += x & 1;
x >>= 1;
}
return ans;
}
vector<vector<int>> t;
vector<int> ans;
void get_ans(int tnode, int tparent, int cubenode) {
ans[tnode] = cubenode;
for (int tneighbour : t[tnode]) {
if (tneighbour == tparent) continue;
get_ans(tneighbour, tnode, cubenode ^ (1 << tneighbour));
}
}
int main()
{
iostream::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
t.resize(n + 1);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
t[x].push_back(y);
t[y].push_back(x);
}
cout << (1 << (n - 1)) << '\n';
ans.resize(n + 1);
for (int start = 0; start < (1 << n); start++) {
if (pop_cnt(start) & 1) continue;
get_ans(n, -1, start);
for (int i = 0; i <= n; i++) cout << ans[i] << ' ';
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |