Submission #658872

# Submission time Handle Problem Language Result Execution time Memory
658872 2022-11-15T09:15:52 Z Foxyy Hiperkocka (COCI21_hiperkocka) C++17
110 / 110
51 ms 3660 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define Foxyy cin.tie(0); cout.sync_with_stdio(0); cout.tie(0);
 
struct Solver {
	int& n;
	vector<vector<int>>& adj;
	
	void solve() {
		if (n == 1) {
			cout << "1\n";
			cout << "0 1\n";
			return;
		}
		vector<int> tree(n+1);
		tree[0] = 0;
		queue<pair<int, int>> q;
		for (int i : adj[0]) {
			q.push({i, 0});
		}
		int cnt = 0;
		while (not q.empty()) {
			auto [u, p] = q.front();
			q.pop();
			tree[u] = tree[p] ^ (1 << cnt);
//			cerr << u << ' ' << p << ' ' << tree[u] << ' ' << tree[p] << '\n';
			cnt++;
			for (int v : adj[u]) if (v != p) {
				q.push({v, u});
			}
		}
		
		vector<int> masks(n-1);
		for (int i = 0; i < n-1; i++) {
			masks[i] = (3 << i);
		}
		
		cout << (1 << (n-1)) << '\n';
		for (int i = 0; i < (1 << (n-1)); i++) {
			int mask = 0;
			for (int j = 0; j < n-1; j++) {
				if ((i >> j) & 1) {
					mask ^= masks[j];
				}
			}
			for (auto x : tree) {
				cout << (x ^ mask) << ' ';
			}
			cout << '\n';
		}
	}
};
 
signed main() {
	Foxyy
	
	int T = 1;
//	cin >> T;
	while(T--) {
		int n;
		cin >> n;
		vector<vector<int>> adj(n+1);
		for (int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		
		Solver solver{n, adj};
		solver.solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 46 ms 3568 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 10 ms 980 KB Output is correct
12 Correct 46 ms 3492 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 48 ms 3600 KB Output is correct
15 Correct 22 ms 1736 KB Output is correct
16 Correct 10 ms 980 KB Output is correct
17 Correct 51 ms 3576 KB Output is correct
18 Correct 46 ms 3532 KB Output is correct
19 Correct 46 ms 3484 KB Output is correct
20 Correct 47 ms 3532 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 46 ms 3592 KB Output is correct
23 Correct 47 ms 3660 KB Output is correct
24 Correct 48 ms 3580 KB Output is correct
25 Correct 51 ms 3600 KB Output is correct
26 Correct 21 ms 1784 KB Output is correct