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;
int main() {
int n; cin >> n;
vector<vector<int>> gp(n);
for (int i = 1; i < n; i++)
{
int u, v; cin >> u >> v;
gp[--v].push_back(--u);
gp[u].push_back(v);
}
int t = 0;
for (int i = 0; i < n; i++) { int a; cin >> a; t += a << i; }
int ans = 2e9;
for (int i = 0; i < (1 << n); i++)
{
int k = t, cnt = 0;
for (int j = 0; j < n; j++)
{
if (i & (1 << j))
{
cnt++;
k ^= (1 << j);
for (int& u : gp[j]) k ^= (1 << u);
}
if (k == 0) ans = min(ans, cnt);
}
}
if (ans == 2e9) cout << "impossible\n";
else cout << ans << endl;
}
# | 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... |