#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 int N = 5e5 + 10;
const int M = 3000;
const int M1 = 1e6;
int n;
map <int, bool> mrk[N];
vector <int> a[N];
vector <int> ans;
vector <vector <int> > ans1;
vector <pair<int, int> > vc;
bool g = 1;
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)
{
ans1.back()[y] = x;
for (auto i : a[y])
if (i != prv)
{
int j;
for (j = 0; j < (1 << n); (j == 0 ? j++ : j <<= 1))
if (!mrk[min(x, j ^ x)][max(j ^ x, x)] && (j ^ x) != x)
{
mrk[min(x, j ^ x)][max(j ^ x, x)] = 1;
vc.pb({min(x, j ^ x), max(j ^ x, x)});
Rec(j ^ x, i, y);
break;
}
g &= (j != (1 << n));
}
}
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);
}
for (int i = 0; i < (1 << n); i++)
{
while (1)
{
ans1.pb({});
ans1.back().resize(n + 1);
vc.clear();
g = 1;
Rec(i, 0, 0);
if (g) continue;
ans1.pop_back();
for (auto j : vc) mrk[j.f][j.s] = 0;
break;
}
}
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 |
Correct |
18 ms |
35552 KB |
Output is correct |
2 |
Partially correct |
17 ms |
35436 KB |
Output is partially correct |
3 |
Partially correct |
17 ms |
35468 KB |
Output is partially correct |
4 |
Partially correct |
19 ms |
35520 KB |
Output is partially correct |
5 |
Partially correct |
18 ms |
35532 KB |
Output is partially correct |
6 |
Partially correct |
18 ms |
35532 KB |
Output is partially correct |
7 |
Partially correct |
18 ms |
35660 KB |
Output is partially correct |
8 |
Partially correct |
18 ms |
35788 KB |
Output is partially correct |
9 |
Partially correct |
582 ms |
69412 KB |
Output is partially correct |
10 |
Partially correct |
47 ms |
38916 KB |
Output is partially correct |
11 |
Partially correct |
99 ms |
42944 KB |
Output is partially correct |
12 |
Partially correct |
514 ms |
69444 KB |
Output is partially correct |
13 |
Partially correct |
23 ms |
36172 KB |
Output is partially correct |
14 |
Partially correct |
716 ms |
68984 KB |
Output is partially correct |
15 |
Partially correct |
185 ms |
51456 KB |
Output is partially correct |
16 |
Partially correct |
102 ms |
42976 KB |
Output is partially correct |
17 |
Partially correct |
469 ms |
68656 KB |
Output is partially correct |
18 |
Partially correct |
511 ms |
69084 KB |
Output is partially correct |
19 |
Correct |
285 ms |
69860 KB |
Output is correct |
20 |
Partially correct |
410 ms |
67512 KB |
Output is partially correct |
21 |
Partially correct |
19 ms |
35820 KB |
Output is partially correct |
22 |
Partially correct |
477 ms |
69268 KB |
Output is partially correct |
23 |
Partially correct |
483 ms |
69224 KB |
Output is partially correct |
24 |
Partially correct |
615 ms |
69272 KB |
Output is partially correct |
25 |
Partially correct |
632 ms |
69008 KB |
Output is partially correct |
26 |
Partially correct |
206 ms |
51524 KB |
Output is partially correct |