#P16964. [SCCPC 2026] 最大权独立集问题

    ID: 19048 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>四川位运算2026省赛/邀请赛

[SCCPC 2026] 最大权独立集问题

Problem Description

Given nn vertices, each vertex has an integer weight WiW_i.

Define that there is an undirected edge between vertices ii and jj if and only if, in the binary representation of WiWjW_i \oplus W_j (where \oplus denotes bitwise XOR), the number of 11 bits is odd.

Please find the maximum weight independent set of this graph. That is, choose a set of vertices such that there is no edge between any two vertices in the set, and the sum of weights of the chosen vertices is as large as possible. The weight of the empty set is defined as 00. You only need to output this maximum total weight.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer tt (1t1051 \le t \le 10^5), which denotes the number of test cases.

For each test case:

The first line contains a positive integer nn (1n5×1051 \le n \le 5 \times 10^5), which denotes the number of vertices.

The second line contains nn positive integers W1,W2,,WnW_1,W_2,\cdots,W_n (1Wi1091 \le W_i \le 10^9), which denote the weights of the vertices.

It is guaranteed that 1n5×1051 \le \sum n \le 5 \times 10^5.

Output Format

For each test case, output one integer per line, representing the maximum total weight of an independent set.

3
5
3 5 15 1 2
3
6 7 11
4
1 2 4 8
23
18
15

Hint

Translated by ChatGPT 5