답안 #522233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522233 2022-02-04T08:47:06 Z blue Hiperkocka (COCI21_hiperkocka) C++17
110 / 110
73 ms 11664 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <string>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const int max_n = 16;

vi edge[1+max_n];

vi parent(1+max_n);
vi fake(1+max_n);
vi actual(1+max_n);
int node_ct = -1;

void dfs(int u, int p)
{
    node_ct++;
    parent[u] = p;
    fake[u] = node_ct;
    actual[node_ct] = u;

    for(int v: edge[u])
    {
        if(p == v) continue;
        dfs(v, u);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    for(int e = 1; e <= n; e++)
    {
        int x, y;
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }

    dfs(0, 0);

    // for(int i = 0; i <= n; i++) cerr << parent[i] << ' ';
    // cerr << '\n';


    //base case: 1 dimension
    vvi a(1, vi{0, 1});

    for(int d = 2; d <= n; d++)
    {
        vvi b1 = a;
        vvi b2 = a;
        for(int i = 0; i < (1 << (d-2)); i++)
        {
            for(int j = 0; j <= d-1; j++)
            {
                b2[i][j] = b2[i][j] ^ (1 << (d-1)) ^ (1 << (d-2));
            }

            a.push_back(b2[i]);
        }

        // cerr << fake[parent[actual[d]]] << '\n';

        // cerr << "preliminary: \n";
        // for(auto f: a)
        // {
        //     for(int g: f) cerr << g << ' ';
        //     cerr << '\n';
        // }
        // cerr << '\n';

        // a.clear();

        // a.push_back(b1[i]);
        for(int i = 0; i < (1 << (d-1)); i++)
        {
            a[i].push_back(a[i][ fake[ parent[ actual[d] ] ] ] ^ (1 << (d-1)));
            // cerr << "pushing back " << (a[i][fake[parent[actual[d]]]] ^ (1 << (d-1))) << '\n';
        }

        // cerr << "post: \n";
        // for(auto f: a)
        // {
        //     for(int g: f) cerr << g << ' ';
        //     cerr << '\n';
        // }
        // cerr << '\n';
    }
    // cerr << "\n\n\n\n";

    // for(int i = 0; i <= n; i++) cerr << parent[i] << ' ' << fake[i] << ' ' << actual[i] <<  '\n';



    // cerr << "\n\n\n\n";






    cout << (1 << (n-1)) << '\n';
    for(int k = 0; k < (1 << (n-1)); k++)
    {
        for(int i = 0; i <= n; i++)
        {
            // cout << a[k][i] << "/" << actual[a[k][i]] << ' ';
            cout << a[k][fake[i]] << ' ';
        }
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 51 ms 11508 KB Output is correct
10 Correct 6 ms 1484 KB Output is correct
11 Correct 12 ms 2820 KB Output is correct
12 Correct 57 ms 11660 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 52 ms 11664 KB Output is correct
15 Correct 24 ms 5704 KB Output is correct
16 Correct 11 ms 2868 KB Output is correct
17 Correct 56 ms 11540 KB Output is correct
18 Correct 51 ms 11576 KB Output is correct
19 Correct 53 ms 11568 KB Output is correct
20 Correct 70 ms 11600 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 51 ms 11552 KB Output is correct
23 Correct 73 ms 11612 KB Output is correct
24 Correct 54 ms 11596 KB Output is correct
25 Correct 57 ms 11636 KB Output is correct
26 Correct 27 ms 5648 KB Output is correct