#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
vector<int>adj[20],old[20];
int par[20];
int surreal[20];
int fake[20];
int bruh;
void dfs(int node, int prv) {
surreal[bruh] = node;
fake[node] = bruh;
bruh++;
for(int x: old[node]) {
if(x != prv) {
dfs(x, node);
}
}
}
void dfs2(int node, int prv) {
par[node] = prv;
for(int x: adj[node]) {
if(x != prv) dfs2(x, node);
}
}
void solve(int tc) {
int n;
cin >> n;
for(int i=1; i<=n; i++) {
int u, v;
cin >> u >> v;
old[u].push_back(v);
old[v].push_back(u);
}
dfs(0, -1);
for(int i=0; i<=n; i++) {
for(int x: old[surreal[i]]) {
adj[i].push_back(fake[x]);
}
}
dfs2(0, -1);
int ans[(1<<(n-1))][n+1];
ans[0][0]=0;
ans[0][1]=1;
for(int i=2; i<=n; i++) {
int bruh = (1 << (i-2)) ^ (1 << (i-1));
for(int j=(1<<(i-2)); j<(1<<(i-1)); j++) {
for(int k=0; k<i; k++) {
ans[j][k] = ans[j-(1<<(i-2))][k] ^ bruh;
}
}
for(int j=0; j<(1<<(i-1)); j++) {
ans[j][i] = ans[j][par[i]] ^ (1<<(i-1));
}
}
cout << (1<<(n-1)) << "\n";
for(int i=0; i<(1<<(n-1)); i++) {
int reword[n+1];
for(int j=0; j<=n; j++) {
reword[surreal[j]] = ans[i][j];
}
for(int j=0; j<=n; j++) {
cout << reword[j] << " \n"[j==n];
}
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
7844 KB |
Output is correct |
10 |
Correct |
4 ms |
980 KB |
Output is correct |
11 |
Correct |
12 ms |
1968 KB |
Output is correct |
12 |
Correct |
42 ms |
7808 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
35 ms |
7928 KB |
Output is correct |
15 |
Correct |
21 ms |
3780 KB |
Output is correct |
16 |
Correct |
9 ms |
1912 KB |
Output is correct |
17 |
Correct |
39 ms |
7916 KB |
Output is correct |
18 |
Correct |
43 ms |
7856 KB |
Output is correct |
19 |
Correct |
35 ms |
7912 KB |
Output is correct |
20 |
Correct |
35 ms |
7884 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
35 ms |
7844 KB |
Output is correct |
23 |
Correct |
37 ms |
7884 KB |
Output is correct |
24 |
Correct |
33 ms |
7876 KB |
Output is correct |
25 |
Correct |
39 ms |
7884 KB |
Output is correct |
26 |
Correct |
17 ms |
3796 KB |
Output is correct |