#P10367. [PA 2024] Żarówki
[PA 2024] Żarówki
Background
PA 2024 5C2
Problem Description
This problem is translated from PA 2024 Round 5 Żarówki. Thanks to Macaronlin for providing the translation.
There are light bulbs. Each bulb has two states: on and off, and the initial state is given. There are switches. Each switch controls two bulbs. Pressing a switch will flip these two bulbs to the opposite of their current states, but it works only when the two bulbs are in the same state; otherwise, it has no effect.
You may choose the order of using switches and the number of times to use them freely. Ask how many different configurations can be achieved using these switches. If a bulb is on in one configuration and off in another, then the two configurations are considered different.
Input Format
The first line contains two integers and , representing the number of bulbs and switches.
The second line contains integers . If , then bulb is initially on; if , then bulb is initially off.
The next lines each contain two integers , describing a switch.
It is guaranteed that each switch affects a different unordered pair of bulbs. Formally, , we have and .
Output Format
Output one integer on a single line, representing how many configurations can be achieved using these switches. Output the answer modulo .
5 4
1 0 1 1 0
1 3
5 3
4 2
1 5
4
Hint
All achievable configurations are: 10110, 00010, 00111, and 10011.
Translated by ChatGPT 5