제출 #986240

#제출 시각아이디문제언어결과실행 시간메모리
986240dorjderemThe Xana coup (BOI21_xanadu)C++17
0 / 100
430 ms524288 KiB
#include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <bitset> using namespace std; #define ull unsigned long long int main() { int n; cin >> n; vector<vector<int>> adj(n); int a, b; for (int i = 0; i < n - 1; ++i) { cin >> a >> b; --a; --b; adj[a].push_back(b); adj[b].push_back(a); } ull state = 0; for (int i = 0; i < n; ++i) { int temp; cin >> temp; if (temp == 1) { state |= (1ULL << i); } } queue<tuple<int, ull, ull>> q; for (int i = 0; i < n; i++) q.push(make_tuple(i, state, 0)); int level = 0; while (!q.empty() && level < 6) { int q_size = q.size(); for (int j = 0; j < q_size; ++j) { auto [node, current_state, visited_bits] = q.front(); q.pop(); if (current_state == 0) { cout << level << endl; return 0; } ull temp_state = current_state; temp_state ^= (1 << node); for (ull nxt : adj[node]) { temp_state ^= (1 << nxt); } for (int k = 0; k < n; k++) { if ((visited_bits & (1 << k)) == 0) { int temp_vis = visited_bits; temp_vis |= (1 << k); q.push(make_tuple(k, temp_state, temp_vis)); } } } ++level; } 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...