結果

問題 No.2800 Game on Tree Inverse
ユーザー 👑 potato167potato167
提出日時 2024-06-21 03:35:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,975 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 218,808 KB
実行使用メモリ 87,268 KB
最終ジャッジ日時 2024-06-21 03:36:20
合計ジャッジ時間 21,320 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 349 ms
37,588 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 349 ms
85,660 KB
testcase_10 WA -
testcase_11 AC 417 ms
86,364 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 365 ms
84,968 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 390 ms
85,100 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 355 ms
86,172 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 396 ms
53,312 KB
testcase_33 WA -
testcase_34 AC 371 ms
85,580 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int D = 18;

struct node{
	int sum = 0;
	int depth = D - 1;
	array<int, 2> to = {-1, -1};
};

int f(int a,int d){
	return (a & (1 << d)) != 0;
}

vector<node> nodes;

struct binary{
	int root;
	int C = 0;
	binary(){
		root = nodes.size();
		node tmp;
		nodes.push_back(tmp);
	}
	bool get(int a){
		a ^= C;
		int ind = root;
		while (nodes[ind].depth != -1){
			int b = f(a, nodes[ind].depth);
			if (nodes[ind].to[b] == -1) return false;
			ind = nodes[ind].to[b];
		}
		return true;
	}
	void set(int a){
		if (get(a)) return;
		a ^= C;
		int ind = root;
		while (nodes[ind].depth != -1){
			nodes[ind].sum++;
			int b = f(a, nodes[ind].depth);
			if (nodes[ind].to[b] == -1){
				nodes[ind].to[b] = nodes.size();
				node tmp;
				tmp.depth = nodes[ind].depth - 1;
				nodes.push_back(tmp);
			}
			ind = nodes[ind].to[b];
		}
		nodes[ind].sum++;
	}
	int mim(){
		int ans = 0;
		int ind = root;
		while (ind != -1 && nodes[ind].depth != -1){
			int b = f(C, nodes[ind].depth);
			int d = nodes[ind].to[b];
			if (d != -1 && nodes[d].sum == (1 << nodes[ind].depth)){
				ans += (nodes[d].sum);
				ind = nodes[ind].to[1 - b];
			}
			else{
				ind = d;
			}
		}
		return ans;
	}
	vector<int> get_list(){
		vector<int> res;
		auto f = [&](auto self, int ind, int val) -> void {
			if (ind == -1) return;
			if (nodes[ind].depth == 0){
				res.push_back(val ^ C);
				return;
			}
			for (int i = 0; i < 2; i++){
				self(self, nodes[ind].to[i], val + i * (1 << nodes[ind].depth));
			}
		};
		f(f, root, 0);
		return res;
		
	}
};

int main(){
	int N;
	cin >> N;
	vector<vector<int>> G(N);
	for (int i = 0; i < N - 1; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> order = {0}, pare(N, -1);
	pare[0] = -2;
	for (int i = 0; i < N; i++){
		int a = order[i];
		for (auto x : G[a]) if (pare[x] == -1){
			order.push_back(x);
			pare[x] = a;
		}
	}
	vector<binary> dp(N);
	vector<int> val(N), ans, wei(N, 1);
	for (int i = N - 1; i >= 0; i--){
		int a = order[i];
		int ind = -1;
		int sum = 0;
		for (auto x : G[a]) if (pare[x] == a){
			sum ^= val[x];
			wei[a] += wei[x];
			if (ind == -1 || wei[x] > wei[ind]) ind = x;
		}
		if (ind != -1){
			dp[ind].C ^= (sum ^ val[ind]);
			swap(dp[ind], dp[a]);
		}
		for (auto x : G[a]) if (pare[x] == a && x != ind){
			dp[x].C ^= (sum ^ val[x]);
			for (auto y : dp[x].get_list()){
				dp[a].set(y);
			}
		}
		dp[a].set(sum);
		val[a] = dp[a].mim();
	}
	auto dfs = [&](auto self, int ind, int v) -> void {
		for (auto x : G[ind]) if (pare[x] == ind){
			v ^= val[x];
		}
		if (v == 0) ans.push_back(ind + 1);
		for (auto x : G[ind]) if (pare[x] == ind){
			self(self, x, v ^ val[x]);
		}
	};
	dfs(dfs, 0, 0);
	cout << "Alice\n";
	cout << ans.size() << "\n";
	sort(ans.begin(), ans.end());
	for (int i = 0; i < (int)ans.size(); i++){
		if (i) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}
0