QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#151495 | #6317. XOR Tree Path | UFRJ# | WA | 34ms | 11468kb | C++14 | 1.2kb | 2023-08-26 20:15:03 | 2023-08-26 20:15:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N; cin >> N;
vector<int> A(N); for (int& a : A) cin >> a;
vector<vector<int>> adj(N);
for (int i = 0; i+1 < N; ++i) {
int a, b; cin >> a >> b;
--a, --b;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<vector<int>> dp(N, vector<int>(2));
const int INF = INT_MAX/2;
auto dfs = [&](auto&& self, int cur, int prv) -> void {
dp[cur] = {0, -INF};
bool is_leaf = true;
for (int nxt : adj[cur]) {
if (nxt == prv) continue;
self(self, nxt, cur);
is_leaf = false;
vector<int> ndp(2, -INF);
for (int a = 0; a < 2; ++a) {
for (int b = 0; b < 2; ++b) {
ndp[a^b] = max(ndp[a^b], dp[cur][a] + dp[nxt][b]);
}
}
dp[cur].swap(ndp);
}
if (is_leaf) {
dp[cur] = {0, 1};
} else {
dp[cur][A[prv]^1] += 1;
}
};
dfs(dfs, 0, -1);
cout << max(dp[0][0], dp[0][1]) << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3508kb
input:
5 1 0 0 1 0 1 2 1 3 3 4 3 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
6 1 1 0 0 1 0 3 1 2 5 1 2 4 1 2 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
9 1 0 1 0 1 0 1 0 1 2 9 1 2 6 9 3 8 4 5 5 9 2 8 7 8
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: -100
Wrong Answer
time: 34ms
memory: 11468kb
input:
73537 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 1 0 0 1 0 0 0 1 1 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 ...
output:
56278
result:
wrong answer 1st numbers differ - expected: '56486', found: '56278'