#include<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
const int MAXN = 18;
int n, cnt, ret[MAXN];
vector<int> g[MAXN];
void dfs(int v, int p, int cur){
++cnt, ret[v]=cur;
for(int to:g[v]){
if(to==p) continue;
dfs(to, v, cur^(1<<cnt));
}
}
int main(){
scanf("%d", &n);
forn(i, n){
int a, b; scanf("%d %d", &a, &b);
g[a].PB(b), g[b].PB(a);
}
printf("%d\n", 1<<(n-1));
forn(i, 1<<n) if(!(i && (__builtin_popcount(i)&1))){
cnt=-1, dfs(0, 0, i);
forn(j, n+1) printf("%d ", ret[j]);
printf("\n");
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:22:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | int a, b; scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
51 ms |
3556 KB |
Output is correct |
10 |
Correct |
5 ms |
560 KB |
Output is correct |
11 |
Correct |
11 ms |
940 KB |
Output is correct |
12 |
Correct |
50 ms |
3532 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
52 ms |
3512 KB |
Output is correct |
15 |
Correct |
24 ms |
1740 KB |
Output is correct |
16 |
Correct |
11 ms |
980 KB |
Output is correct |
17 |
Correct |
49 ms |
3548 KB |
Output is correct |
18 |
Correct |
51 ms |
3532 KB |
Output is correct |
19 |
Correct |
50 ms |
3572 KB |
Output is correct |
20 |
Correct |
54 ms |
3568 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
50 ms |
3556 KB |
Output is correct |
23 |
Correct |
50 ms |
3556 KB |
Output is correct |
24 |
Correct |
50 ms |
3608 KB |
Output is correct |
25 |
Correct |
51 ms |
3540 KB |
Output is correct |
26 |
Correct |
23 ms |
1748 KB |
Output is correct |