1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, m;

    cin >> n >> m;

    vector<bool> bulbs;
    vector<pair<int, int>> switches;

    for (int i = 0; i < n; i++) {
        int input;
        cin >> input;
        bulbs.push_back(input);
    }

    for (int i = 0; i < m; i++) {
        pair<int, int> pair;
        cin >> pair.first >> pair.second;
        switches.push_back(pair);
    }

    int result = 1;

    for (int i = 0; i < m; i++) {
        vector<bool> tempBulbs = bulbs;
        if (tempBulbs[switches[i].first - 1] == tempBulbs[switches[i].second - 1]) {
            result++;
            tempBulbs[switches[i].first - 1] = !tempBulbs[switches[i].first - 1];
            tempBulbs[switches[i].second - 1] = !tempBulbs[switches[i].second - 1];
        }
        for (int j = i + 1; j < m; j++) {
            if (tempBulbs[switches[j].first - 1] == tempBulbs[switches[j].second - 1]) {
                result++;
            }
        }
    }

    cout << result;
}