답안 #529636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529636 2022-02-23T09:37:54 Z topovik Hiperkocka (COCI21_hiperkocka) C++14
4.8125 / 110
19 ms 12620 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second

using namespace std;

typedef long long ll;
typedef long double ld;

const ll oo = 1e18 + 7;

const ll N = 5e5 + 10;
const ll M = 1000;
const ll M1 = 1e6;

int n;
bool mrk[N];
vector <int> a[N];
vector <int> ans;
vector <vector <int> > ans1;

bool check(int x)
{
    for (int i = 0; i < n; i++)
        if (x == (1 << i)) return 1;
    return 0;
}


void Rec(int x, int y, int prv)
{
//    cout << x << " " << y << " " << prv << endl;
    ans[y] = x;
    mrk[x] = 1;
    for (auto i : a[y])
        if (i != prv)
    {
        for (int j = 1; ; j <<= 1)
            if (!mrk[j ^ x])
        {
            mrk[j ^ x] = 1;
            Rec(j ^ x, i, y);
            break;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x].pb(y);
        a[y].pb(x);
    }
    ans.resize(n + 1);
    Rec(0, 0, 0);
//    cout << "Yes\n";
    ans1.pb(ans);
    for (int x = 0; x < (1 << n); x++)
    {
        bool g = 1;
        for (int i = 0; i <= n; i++) g &= !mrk[ans[i] ^ x];
        if (g)
        {
            ans1.pb(ans);
            for (int i = 0; i <= n; i++) ans1.back()[i] ^= x;
            for (int i = 0; i <= n; i++) mrk[ans1.back()[i]] = 1;
        }
    }
    cout << ans1.size() << endl;
    for (auto i : ans1)
    {
        for (auto j : i) cout << j << " ";
        cout << endl;
    }
}
/*
5 3
2 1 1 2 2 3
2 3 3 4 4 5
4 1 1 2 2 3 3 4 4 5
*/
# 결과 실행 시간 메모리 Grader output
1 Partially correct 8 ms 11980 KB Output is partially correct
2 Partially correct 7 ms 11964 KB Output is partially correct
3 Partially correct 6 ms 11980 KB Output is partially correct
4 Partially correct 6 ms 11960 KB Output is partially correct
5 Partially correct 6 ms 11980 KB Output is partially correct
6 Partially correct 8 ms 12056 KB Output is partially correct
7 Partially correct 6 ms 12020 KB Output is partially correct
8 Partially correct 7 ms 11980 KB Output is partially correct
9 Partially correct 14 ms 12500 KB Output is partially correct
10 Partially correct 8 ms 12108 KB Output is partially correct
11 Partially correct 10 ms 12448 KB Output is partially correct
12 Partially correct 14 ms 12480 KB Output is partially correct
13 Partially correct 7 ms 11980 KB Output is partially correct
14 Partially correct 13 ms 12480 KB Output is partially correct
15 Partially correct 12 ms 12492 KB Output is partially correct
16 Partially correct 9 ms 12248 KB Output is partially correct
17 Partially correct 13 ms 12452 KB Output is partially correct
18 Partially correct 12 ms 12440 KB Output is partially correct
19 Partially correct 13 ms 12492 KB Output is partially correct
20 Partially correct 13 ms 12440 KB Output is partially correct
21 Partially correct 7 ms 11980 KB Output is partially correct
22 Partially correct 13 ms 12484 KB Output is partially correct
23 Partially correct 13 ms 12620 KB Output is partially correct
24 Partially correct 15 ms 12436 KB Output is partially correct
25 Partially correct 13 ms 12452 KB Output is partially correct
26 Partially correct 19 ms 12496 KB Output is partially correct