#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 17;
int gde[(1<<N)][N+1];
vector <int> ord, parent;
vector <int> graf[N+1];
void dfs(int v, int p){
ord.push_back(v);
parent.push_back(p);
for(auto c : graf[v]){
if(c != p) dfs(c, v);
}
}
bool taken[(1<<N)];
vector <int> vc;
void dupliraj(int n, int v, int p){
vc.push_back(v);
for(int i=0; i<n; i++){
gde[i][v] = gde[i][p] + 2*n;
taken[gde[i][v]] = 1;
}
int k = 2*n;
for(int i=0; i<n; i++){
while(taken[k]) k++;
int xr = k^gde[i][p];
for(int j=0; j<vc.size(); j++){
gde[i + n][vc[j]] = gde[i][vc[j]] ^ xr;
}
taken[k] = 1;
}
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
for(int i=1; i<=n; i++){
int a, b;
cin >> a >> b;
graf[a].push_back(b);
graf[b].push_back(a);
}
dfs(0, -1);
reverse(ord.begin(), ord.end());
reverse(parent.begin(), parent.end());
ord.pop_back();
parent.pop_back();
gde[0][0] = 0;
gde[0][ord.back()] = 1;
vc.push_back(0);
vc.push_back(ord.back());
ord.pop_back();
parent.pop_back();
int tren = 1;
while(ord.size()){
dupliraj(tren, ord.back(), parent.back());
tren *= 2;
ord.pop_back();
parent.pop_back();
}
cout << (1<<(n-1)) << "\n";
for(int i=0; i<(1<<(n-1)); i++){
for(int j=0; j<=n; j++){
cout << gde[i][j] << " ";
}
cout << "\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'void dupliraj(int, int, int)':
Main.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int j=0; j<vc.size(); j++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
44 ms |
5856 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
11 ms |
1576 KB |
Output is correct |
12 |
Correct |
47 ms |
5888 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
45 ms |
5880 KB |
Output is correct |
15 |
Correct |
21 ms |
2880 KB |
Output is correct |
16 |
Correct |
10 ms |
1484 KB |
Output is correct |
17 |
Correct |
47 ms |
5860 KB |
Output is correct |
18 |
Correct |
47 ms |
5956 KB |
Output is correct |
19 |
Correct |
46 ms |
5952 KB |
Output is correct |
20 |
Correct |
45 ms |
5956 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
45 ms |
5932 KB |
Output is correct |
23 |
Correct |
47 ms |
5964 KB |
Output is correct |
24 |
Correct |
45 ms |
5916 KB |
Output is correct |
25 |
Correct |
56 ms |
5964 KB |
Output is correct |
26 |
Correct |
22 ms |
3004 KB |
Output is correct |