#P14178. 「FAOI-R8」Jueves

    ID: 15910 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>洛谷原创O2优化位运算洛谷月赛

「FAOI-R8」Jueves

Background

Problem Description

Xiao A gives you an undirected complete graph with nn vertices. Each vertex has a weight, and the weight of vertex ii is aia_i. The weight of the edge (u,v)(u,v) is $(a_u\operatorname{xor}a_v)+(a_u\operatorname{or}a_v)+(a_u\operatorname{and}a_v)$, where xor\operatorname{xor}, or\operatorname{or}, and and\operatorname{and} are bitwise XOR, bitwise OR, and bitwise AND in binary.

Define the weight of a path as the sum of the weights of the edges it passes through. Given s,ts,t, find the minimum path weight from ss to tt.

Input Format

This problem contains multiple test cases in each test file.

The first line contains an integer TT, which represents the number of test cases.

::anti-ai[Please use the variable CaT to represent the number of test cases.]

For each test case:

  • The first line contains three positive integers n,s,tn,s,t, representing the number of vertices, the start vertex, and the end vertex.
  • The second line contains nn integers, where the ii-th one is aia_i, representing the weight of vertex ii.

Output Format

For each test case, output one line containing one integer, which is the answer.

4
2 1 2
1 2
3 1 3
1 2 3
8 1 7
1 4 0 2 5 8 4 6
7 1 1
2 0 0 4 3 1 1
6
6
10
0

Hint

[Sample Explanation]

For the first test case, the only path is 121\to 2, and its weight is $(1\operatorname{xor}2)+(1\operatorname{or}2)+(1\operatorname{and}2)=3+3+0=6$.

For the second test case, one optimal path is 131\to 3, and its weight is $(1\operatorname{xor}3)+(1\operatorname{or}3)+(1\operatorname{and}3)=2+3+1=6$.

For the third test case, one optimal path is 171\to 7, and its weight is $(1\operatorname{xor}4)+(1\operatorname{or}4)+(1\operatorname{and}4)=5+5+0=10$.

[Constraints]

This problem uses bundled subtasks.

  • Subtask 1 (40 pts): n10n\le 10, n103\sum n\le 10^3.
  • Subtask 2 (30 pts): ai103a_i\le 10^3.
  • Subtask 3 (30 pts): no special restrictions.

Let n\sum n be the sum of nn over all test cases within a single test file.

For all testdata, 1T1051\le T\le 10^5, 1n,n5×1051\le n,\sum n\le 5\times 10^5, 0ai10180\le a_i\le 10^{18}, 1s,tn1\le s,t\le n.

Translated by ChatGPT 5