Submission #797371

#TimeUsernameProblemLanguageResultExecution timeMemory
797371cig32Hiperkocka (COCI21_hiperkocka)C++17
110 / 110
43 ms7928 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int MAXN = 1e6 + 10; const int MOD = 1e9 + 7; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } vector<int>adj[20],old[20]; int par[20]; int surreal[20]; int fake[20]; int bruh; void dfs(int node, int prv) { surreal[bruh] = node; fake[node] = bruh; bruh++; for(int x: old[node]) { if(x != prv) { dfs(x, node); } } } void dfs2(int node, int prv) { par[node] = prv; for(int x: adj[node]) { if(x != prv) dfs2(x, node); } } void solve(int tc) { int n; cin >> n; for(int i=1; i<=n; i++) { int u, v; cin >> u >> v; old[u].push_back(v); old[v].push_back(u); } dfs(0, -1); for(int i=0; i<=n; i++) { for(int x: old[surreal[i]]) { adj[i].push_back(fake[x]); } } dfs2(0, -1); int ans[(1<<(n-1))][n+1]; ans[0][0]=0; ans[0][1]=1; for(int i=2; i<=n; i++) { int bruh = (1 << (i-2)) ^ (1 << (i-1)); for(int j=(1<<(i-2)); j<(1<<(i-1)); j++) { for(int k=0; k<i; k++) { ans[j][k] = ans[j-(1<<(i-2))][k] ^ bruh; } } for(int j=0; j<(1<<(i-1)); j++) { ans[j][i] = ans[j][par[i]] ^ (1<<(i-1)); } } cout << (1<<(n-1)) << "\n"; for(int i=0; i<(1<<(n-1)); i++) { int reword[n+1]; for(int j=0; j<=n; j++) { reword[surreal[j]] = ans[i][j]; } for(int j=0; j<=n; j++) { cout << reword[j] << " \n"[j==n]; } } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); } // 勿忘初衷
#Verdict Execution timeMemoryGrader output
Fetching results...