# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647911 | thorie | The Xana coup (BOI21_xanadu) | C++17 | 1094 ms | 7092 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
vector<vector<int>> graph;
vector<bool> on;
vector<bool> onCopy;
void toggle(int k) {
on[k] = !on[k];
for (int i = 0; i < graph[k].size(); i++) {
on[graph[k][i]] = !on[graph[k][i]];
}
}
int main() {
int n;
cin >> n;
graph.resize(n);
on.resize(n);
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
graph[a - 1].push_back(b - 1);
graph[b - 1].push_back(a - 1);
}
for (int i = 0; i < n; i++) {
bool a;
cin >> a;
on[i] = a;
}
onCopy = on;
int m = INT_MAX;
for (int i = 0; i < 1 << n; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (i & 1 << j) {
toggle(j);
cnt++;
}
}
bool allFalse = true;
for (int j = 0; j < n; j++) {
if (on[j]) {
allFalse = false;
break;
}
}
if (allFalse) {
m = min(m, cnt);
}
on = onCopy;
}
if (m == INT_MAX) {
cout << "impossible" << endl;
}
else {
cout << m << endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |