#P11562. 【MX-X7-T3】[LSOT-3] 寄存器
【MX-X7-T3】[LSOT-3] 寄存器
Background
Original link: https://oier.team/problems/X7D.
This is not APIO, so this problem is not asking you to build a CPU by hand.
Problem Description
There are registers, numbered . These registers are connected by wires with switches. To ensure smooth information exchange, it is guaranteed that every pair of registers can be connected through some wires.
Initially, the information stored in every register is . Each time, Xiao H can independently toggle the switches of all wires, and then choose one register to power on. If a register is connected to a powered register by an enabled wire, then this register will also be powered on. All powered registers will flip their stored information ( becomes , and becomes ). Xiao H wants the registers to store the information he wants, and he wants you to tell him the minimum number of power-on operations needed.
Input Format
The first line contains a positive integer , representing the number of registers.
The second line contains non-negative integers , where means Xiao H wants register to store . It is guaranteed that is either or .
The next lines each contain two positive integers , indicating that there is a wire between registers and . It is guaranteed that every pair of registers can be connected through some wires.
Output Format
Output a single line containing a non-negative integer, representing the minimum number of power-on operations.
5
1 0 0 1 0
1 2
2 3
2 4
3 5
2
15
1 0 0 0 0 1 0 1 1 1 0 0 1 1 0
10 2
1 7
1 5
9 7
14 2
4 11
6 5
9 15
4 5
5 3
5 14
13 5
5 8
5 12
4
Hint
Sample Explanation #1
First, turn off wire and turn on all the others, then power on register . At this time, the information in is flipped, and the information stored in all registers becomes 1 0 0 0 0.
Then, turn off wire and turn on all the others, then power on register . At this time, the information in is flipped, and the information stored in all registers becomes 1 0 0 1 0, which meets the requirement.
It can be proven that there is no better solution.
Constraints
This problem uses bundled testdata.
- Subtask 1 (20 points): .
- Subtask 2 (20 points): For the -th wire, , .
- Subtask 3 (30 points): There does not exist a pair of adjacent registers that want to store the same information.
- Subtask 4 (30 points): No special properties.
For all testdata: , , , and every pair of registers can be connected through some wires.
Translated by ChatGPT 5