#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, path[N];
vector<int> g[N];
vector<pair<int, int>> edges;
void dfs(int v, int p = -1){
for (int e : g[v]){
int u = edges[e].first + edges[e].second - v;
if (u == p) continue;
path[u] = path[v] ^ (1 << e);
dfs(u, v);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i ++){
int u, v;
cin >> u >> v;
g[u].push_back(i);
g[v].push_back(i);
edges.push_back({u, v});
}
dfs(0);
cout << (1 << (n - 1)) << endl;
for (int r = 0; r < (1 << n); r ++){
if (__builtin_popcount(r) % 2) continue;
for (int i = 0; i <= n; i ++)
cout << (path[i] ^ r) << " ";
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
3920 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
12 ms |
1116 KB |
Output is correct |
12 |
Correct |
31 ms |
3672 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
29 ms |
3664 KB |
Output is correct |
15 |
Correct |
14 ms |
1744 KB |
Output is correct |
16 |
Correct |
14 ms |
1112 KB |
Output is correct |
17 |
Correct |
29 ms |
3528 KB |
Output is correct |
18 |
Correct |
53 ms |
3664 KB |
Output is correct |
19 |
Correct |
30 ms |
3668 KB |
Output is correct |
20 |
Correct |
50 ms |
3696 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
29 ms |
3524 KB |
Output is correct |
23 |
Correct |
41 ms |
3664 KB |
Output is correct |
24 |
Correct |
31 ms |
3668 KB |
Output is correct |
25 |
Correct |
40 ms |
3568 KB |
Output is correct |
26 |
Correct |
20 ms |
1884 KB |
Output is correct |