#P5406. [THUPC 2019] 找树
[THUPC 2019] 找树
Description
Define as bitwise AND, bitwise OR, and bitwise XOR, respectively. Let denote the -th binary bit of from low to high. Define a new operation on -bit binary numbers such that for each bit of the result , we have . It is not hard to verify that the operation is associative and commutative.
Given an undirected graph with vertices and edges, each edge weight is a -bit binary number (i.e., a non-negative integer less than ). Please find a spanning tree of the original graph. Suppose the edge weights in your spanning tree are . Please maximize .
Input Format
The first line contains two positive integers .
The second line contains a string of length . Each character in the string is one of &, |, ^ (representing AND, OR, XOR, respectively), indicating each .
The next lines each contain three non-negative integers , representing an edge connecting and with weight . It is guaranteed that , .
For all testdata, .
Output Format
Output one line with one number, indicating the answer. If the graph is disconnected, output -1.
3 3
^
1 2 1
2 3 1
1 3 0
1
Hint
About the testdata
For some reasons, the testdata only keeps the last vertices.
Copyright information
From THUPC (THU Programming Contest, Tsinghua University Programming Contest) 2019.
Resources such as solutions can be found at https://github.com/wangyurzee7/THUPC2019.
Translated by ChatGPT 5
京公网安备 11011102002149号