#P16596. 【四川省集】仙人掌最小值查询

    ID: 18911 远端评测题 1500ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>四川仙人掌线性基2026圆方树

【四川省集】仙人掌最小值查询

Problem Description

Given a connected undirected edge cactus graph with edge weights, answer multiple queries. For each query, find the minimum possible XOR sum of edge weights along a vertex-simple (no repeated vertices) path between two given nodes.

Note: The original graph may contain multiple edges and self-loops. A cycle formed by a pair of parallel edges is also considered a cycle. Self-loops clearly do not affect this problem.

Input Format

The first line contains three integers n,m,kn,m,k, where nn is the number of vertices, mm is the number of edges, and kk is the number of queries.

The next mm lines each contain three integers li,ri,vil_i,r_i,v_i, meaning there is an edge between lil_i and rir_i with weight viv_i.

The next kk lines each contain two integers li,ril_i,r_i, meaning: query the minimum XOR value of edge weights over all vertex-simple paths between lil_i and rir_i.

Output Format

Output kk lines. Each line contains one integer, the answer to the ii-th query in order.

4 4 3
1 2 1
2 3 2
3 4 3
4 2 4
1 4
1 3
2 4
0
3
1

Hint

Sample Explanation

The first query: 1234,123=01\to2\to3\to4,1\bigoplus2\bigoplus3=0.

The second query: 123,12=31\to2\to3,1\bigoplus2=3.

The third query: 23=12\bigoplus3=1.

Constraints

For all testdata, n5×105,k105,v109n\le5\times10^5,k\le10^5,v\le10^9. The detailed constraints are as follows:

Subtask nn\le kk\le vv\le Score
00 1010 5050 2512^{5}-1 1010
11 100100 30003000 21512^{15}-1 2020
22 10410^4 10510^5 22012^{20}-1 3030
33 5×1055\times10^5 23012^{30}-1 4040

Special Notes

The testdata for this problem is not easy to create, and there are many wrong solutions or solutions with too high time complexity, so it may be quite strict on constant factors. You are welcome to submit hack testdata.

Currently, common wrong solutions that are not guaranteed to be hacked include:

  1. Let me see whether nklogVnk\log V can pass.
  2. I think heavy-light decomposition with klog4k\log^4 can pass.
  3. I guess long-chain decomposition / binary lifting linear basis with klog3k\log^3 can pass.
  4. I think (nlogn)43(n\log n)^{\frac{4}{3}} tree blocking + linear basis can pass.
  5. Various boundary issues, and so on.

Translated by ChatGPT 5