제출 #782824

#제출 시각아이디문제언어결과실행 시간메모리
782824christinelynnThe Xana coup (BOI21_xanadu)C++17
5 / 100
125 ms6232 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second

vector<int> adj[100005];
int a[100005];

int main() { 
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n <= 20) {
        for (int i = 1; i <= n; i++) adj[i].push_back(i);
        int ans = n + 1;
        for (int i = 0; i < (1 << n); i++) {
            int tm = 0;
            for (int j = 0; j < n; j++) {
                if ((1 << j) & i) for (auto x : adj[j + 1]) tm ^= (1 << (x - 1));
            }
            for (int j = 0; j < n; j++) if (a[j + 1]) tm ^= (1 << j);
            if (tm != 0) continue;
            int cnt = 0;
            for (int j = 0; j < n; j++) if ((1 << j) & i) cnt++;
            ans = min(ans, cnt);
        }
        if (ans == n + 1) cout << "impossible\n";
        else cout << ans << "\n";
    }
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...