#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<pair<int,int>> graf[20];
map<pair<int,int>,bool> jest;
int wart[20];
void dfs (int v, int p){
for (pair<int,int> x:graf[v]){
if (x.first!=p){
wart[x.first]= wart[v] ^ (1<<x.second);
dfs(x.first,v);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,a,b;
cin >> n;
for (int x=1;x<=n;x++){
cin >> a >> b;
graf[a].push_back({b,x-1});
graf[b].push_back({a,x-1});
}
dfs(0,-1);
for (int x=0;x<(1<<n);x++){
for (int y=0;y<n;y++){
jest[{x,x^(1<<y)}]=1;
}
}
vector<vector<int>> wyniki;
for (int x=0;x<(1<<n);x++){
bool git=1;
for (int y=0;y<n;y++){
for (pair<int,int> z:graf[y]){
a = wart[y] ^ x; b = wart[z.first]^x;
if (!jest[{a,b}])git=0;
}
}
if (git){
vector<int> empt;
wyniki.push_back(empt);
for (int y=0;y<n;y++){
wyniki.back().push_back(wart[y]^x);
for (pair<int,int> z:graf[y]){
a = wart[y] ^ x; b = wart[z.first]^x;
jest[{a,b}]=0;
jest[{b,a}]=0;
}
}
wyniki.back().push_back(wart[n]^x);
}
}
cout << wyniki.size() << '\n';
for (int x=0;x<wyniki.size();x++){
for (int y:wyniki[x]) cout << y << ' ';
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |