Submission #548123

# Submission time Handle Problem Language Result Execution time Memory
548123 2022-04-12T13:43:03 Z aryan12 Hiperkocka (COCI21_hiperkocka) C++17
110 / 110
53 ms 3660 KB
 #include <bits/stdc++.h>
 using namespace std;
 #define int long long
 
 mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
int n;
const int N = 17;
vector<pair<int, int> > g[N];
int val[N];

int power(int a, int b)
{
 	if(b == 0)
 	{
 		return 1;
 	}
 	if(b == 1)
 	{
 		return a;
 	}
 	int x = power(a, b / 2);
 	x *= x;
 	if(b & 1)
 	{
 		x *= a;
 	}
 	return x;
}

void dfs(int node, int par)
{
	for(auto [to, wt]: g[node])
	{
		if(to == par) continue;
		val[to] = val[node] ^ wt;
		dfs(to, node);
	}
}

void Solve() 
{
 	cin >> n;
 	for(int i = 0; i < n; i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		g[u].push_back(make_pair(v, power(2, i)));
 		g[v].push_back(make_pair(u, power(2, i)));
 	}
 	val[0] = 0;
 	dfs(0, -1);
 	cout << power(2, n - 1) << "\n";
 	for(int i = 0; i <= n; i++)
 	{
 		cout << val[i] << " ";
 	}
 	cout << "\n";
 	for(int i = 1; i < (1 << n); i++) 
 	{
 		if(__builtin_popcount(i) % 2 == 0)
 		{
 			for(int j = 0; j <= n; j++)
 			{
 				cout << (val[j] ^ i) << " ";
 			}
 			cout << "\n";
 		}
 	}
}
 
 int32_t main() 
 {
 	auto begin = std::chrono::high_resolution_clock::now();
 	ios_base::sync_with_stdio(0);
 	cin.tie(0);
 	int t = 1;
 	//cin >> t;
 	for(int i = 1; i <= t; i++) 
 	{
 		//cout << "Case #" << i << ": ";
 		Solve();
 	}
 	auto end = std::chrono::high_resolution_clock::now();
     auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
     cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
 	return 0;
 }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 53 ms 3580 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 9 ms 992 KB Output is correct
12 Correct 37 ms 3512 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 41 ms 3508 KB Output is correct
15 Correct 18 ms 1832 KB Output is correct
16 Correct 8 ms 964 KB Output is correct
17 Correct 38 ms 3532 KB Output is correct
18 Correct 36 ms 3564 KB Output is correct
19 Correct 40 ms 3544 KB Output is correct
20 Correct 36 ms 3532 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 36 ms 3532 KB Output is correct
23 Correct 36 ms 3532 KB Output is correct
24 Correct 37 ms 3532 KB Output is correct
25 Correct 38 ms 3660 KB Output is correct
26 Correct 19 ms 1752 KB Output is correct