#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int countConfig(vector<int>&lights,vector<vector<int>>&switches){
int n=lights.size();
int onCount=0;
for(int light:lights){
onCount+=light;
}
for(auto&switchPair:switches){
int light1=switchPair[0]-1;
int light2=switchPair[1]-1;
if(lights[light1]==lights[light2]){
onCount=(n-onCount)*(onCount!=n);
}
}
return onCount;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> lights(n);
for (int i = 0; i < n; i++) {
cin >> lights[i];
}
vector<vector<int>> switches(m, vector<int>(2));
for (int i = 0; i < m; i++) {
cin >> switches[i][0] >> switches[i][1];
}
int result = countConfig(lights, switches);
cout << result % MOD << endl;
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 | #include <iostream> #include <vector> using namespace std; const int MOD = 1e9 + 7; int countConfig(vector<int>&lights,vector<vector<int>>&switches){ int n=lights.size(); int onCount=0; for(int light:lights){ onCount+=light; } for(auto&switchPair:switches){ int light1=switchPair[0]-1; int light2=switchPair[1]-1; if(lights[light1]==lights[light2]){ onCount=(n-onCount)*(onCount!=n); } } return onCount; } int main() { int n, m; cin >> n >> m; vector<int> lights(n); for (int i = 0; i < n; i++) { cin >> lights[i]; } vector<vector<int>> switches(m, vector<int>(2)); for (int i = 0; i < m; i++) { cin >> switches[i][0] >> switches[i][1]; } int result = countConfig(lights, switches); cout << result % MOD << endl; return 0; } |
English