Submission #986221

#TimeUsernameProblemLanguageResultExecution timeMemory
986221dorjderemThe Xana coup (BOI21_xanadu)C++17
0 / 100
1069 ms524288 KiB
#include <iostream> #include <vector> #include <queue> #include <tuple> #include <algorithm> #include <numeric> using namespace std; int main() { int n; cin >> n; vector<vector<int>> adj(n); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; adj[a - 1].push_back(b - 1); adj[b - 1].push_back(a - 1); } vector<int> state(n); for (int i = 0; i < n; ++i) { cin >> state[i]; } bool found = false; for (int i = 0; i < n; ++i) { queue<pair<int, vector<int>>> q; q.push(make_pair(i, state)); int level = 0; while (!q.empty() && level < 5) { int q_size = q.size(); while (q_size--) { auto front = q.front(); q.pop(); int node = front.first; vector<int> current_state = front.second; if (accumulate(current_state.begin(), current_state.end(), 0) == 0) { cout << level << endl; return 0; } current_state[node] = !current_state[node]; for (int neighbor : adj[node]) { current_state[neighbor] = !current_state[neighbor]; } for (int k = 0; k < n; ++k) { if (k != node) { q.push(make_pair(k, current_state)); } } } ++level; } } if (!found) { cout << "IMPOSSIBLE" << endl; } return 0; }
#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...