QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#392966#6317. XOR Tree PathGiga_Cronos#Compile Error//C++231.3kb2024-04-18 00:38:062024-04-18 00:38:06

Judging History

你现在查看的是最新测评结果

  • [2024-04-18 00:38:06]
  • 评测
  • [2024-04-18 00:38:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN ((ll)(1e5 + 5))

int a[MAXN];
vector<int> g[MAXN];
int dp[MAXN][2];

void dfs(int u, int p) {
	int sum = 0;
	int cnt = 0;
	// cout << "\n";
	// cout << "for " << u << "\n";
	dp[u][1]=-1e6;
	for (auto v : g[u]) {
		if (v == p)
			continue;
		dfs(v, u);
		cnt++;
		sum ^= a[v];
		// cout << "\n";
		// cout << v << ' ' << dp[v][0] << ' ' << dp[v][1] << "\n";
		int v0 = max(dp[u][0] + dp[v][0], dp[u][1] + dp[v][1]);
		int v1 = max(dp[u][0] + dp[v][1], dp[u][0] + dp[v][0]);
		dp[u][0] = v0;
		dp[u][1] = v1;
		// cout << dp[u][0] << ' ' << dp[u][1] << "\n";
	}

	if (!cnt) {
		dp[u][0] = 0;
		dp[u][1] = 1;
		return;
	}
	// cout << u << ' ' << sum << ' ' << a[u] << "\n";
	// cout << dp[u][0] << ' ' << dp[u][1] << "\n";
	if (sum ^ a[u]) {
		swap(dp[u][0], dp[u][1]);
	}
	dp[u][1]++;
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(0, -1);

	// for (int i = 0; i < n; i++) {
	// 	cout << dp[i][0] << ' ' << dp[i][1] << "\n";
	// }

	cout << max(dp[0][0], dp[0][1]) << "\n";

	return 0;dgdfgfb
}

详细

answer.code: In function ‘int32_t main()’:
answer.code:68:18: error: ‘dgdfgfb’ was not declared in this scope
   68 |         return 0;dgdfgfb
      |                  ^~~~~~~