Submission #647911

#TimeUsernameProblemLanguageResultExecution timeMemory
647911thorieThe Xana coup (BOI21_xanadu)C++17
5 / 100
1094 ms7092 KiB
#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)

xanadu.cpp: In function 'void toggle(int)':
xanadu.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < graph[k].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
#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...