이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
int mod = 1e9+7;
ll modulo(ll a) {
return ((a % mod) + mod) % mod;
}
ll add(ll a, ll b) {
return modulo(a + b);
}
ll mult(ll a, ll b) {
return modulo(a * b);
}
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b&1) {
res = mult(res, a);
}
a = mult(a, a);
b >>= 1;
}
return res;
}
const int N = 1e5+7;
vector <int> graph[N];
int color[N];
void check(int n) {
int mn = 2e9;
for (int mask = 0; mask < (1 << n); mask++) {
vector <int> c(n);
for (int i = 0; i < n; i++) c[i] = color[i];
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) {
c[i] ^= 1;
for (auto to : graph[i]) {
c[to] ^= 1;
}
}
}
int flag = 0;
for (int i = 0; i < n; i++) flag |= c[i];
if (!flag) {
mn = min(mn, __builtin_popcount(mask));
}
}
if (mn < 2e9) {
cout << mn << endl;
exit(0);
}
}
void solve() {
int n;
cin >> n;
for (int i = 0; i < n-1; i++) {
int a, b;
cin >> a >> b;
a--; b--;
graph[a].pb(b);
graph[b].pb(a);
}
for (int i = 0; i < n; i++) {
cin >> color[i];
}
check(n);
cout << "impossible" << endl;
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
while (t--) {
solve();
}
return 0;
}
# | 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... |