#include <vector>
#include <iostream>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n, m;
std::cin >> n >> m;
std::vector<bool> bulbs(n + 1, false);
for (int i = 1; i <= n; i++) {
int bulb;
std::cin >> bulb;
if (bulb == 1) {
bulbs[i] = true;
}
}
std::vector<bool> switchableBulbs(n + 1, false);
int count{1};
for (int i = 0; i < m; i++) {
int a;
int b;
std::cin >> a >> b;
if (!(bulbs[a] ^ bulbs[b])) {
switchableBulbs[a] = true;
switchableBulbs[b] = true;
count++;
} else if (switchableBulbs[a]) {
switchableBulbs[b] = true;
count++;
} else if (switchableBulbs[b]) {
switchableBulbs[a] = true;
count++;
}
count %= 1000000007;
}
std::cout << count << "\n";
return 0;
}
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 | #include <vector> #include <iostream> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n, m; std::cin >> n >> m; std::vector<bool> bulbs(n + 1, false); for (int i = 1; i <= n; i++) { int bulb; std::cin >> bulb; if (bulb == 1) { bulbs[i] = true; } } std::vector<bool> switchableBulbs(n + 1, false); int count{1}; for (int i = 0; i < m; i++) { int a; int b; std::cin >> a >> b; if (!(bulbs[a] ^ bulbs[b])) { switchableBulbs[a] = true; switchableBulbs[b] = true; count++; } else if (switchableBulbs[a]) { switchableBulbs[b] = true; count++; } else if (switchableBulbs[b]) { switchableBulbs[a] = true; count++; } count %= 1000000007; } std::cout << count << "\n"; return 0; } |
English