Submission #1282757

#TimeUsernameProblemLanguageResultExecution timeMemory
1282757stefanneaguHiperkocka (COCI21_hiperkocka)C++20
0 / 110
1 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

const int nmax = (1 << 16) + 1;

vector<pair<int, int>> adj[nmax];
int timer = 0;
int to[nmax];

void dfs_init(int i, int tata = -1) {
    for (auto &[it, c] : adj[i]) {
        if (it == tata) {
            continue;
        }
        c = timer++;
        dfs_init(it, i);
    }
}

void dfs(int i, int val, int tata = -1) {
    for (auto [it, c] : adj[i]) {
        if (it == tata) {
            continue;
        }
        to[it] = val ^ (1 << c);
        dfs(it, (val ^ (1 << c)), i);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back({b, 0});
        adj[b].push_back({a, 0});
    }
    dfs_init(0);
    cout << (1 << (n - 1)) << '\n';
    for (int i = 0; i < (1 << n); i += 2) {
        to[0] = i;
        dfs(0, i);
        for (int j = 0; j <= n; j++) {
            cout << to[j] << " ";
        }
        cout << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...