From c90f7050603204d7229b843cdea51bc3076ce6d3 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Feb 2023 21:48:44 +0800 Subject: [PATCH] =?UTF-8?q?P5227=20[AHOI2013]=E8=BF=9E=E9=80=9A=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/101799398 --- Luogu/P5227/P5227.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Luogu/P5227/P5227.cpp diff --git a/Luogu/P5227/P5227.cpp b/Luogu/P5227/P5227.cpp new file mode 100644 index 00000000..1005c413 --- /dev/null +++ b/Luogu/P5227/P5227.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5, + M = 2e5 + 5; + +int n, m, q, s[N], d[M]; +std::mt19937 rng(std::random_device{}()); +std::vector> g[N]; +bool vis[N]; + +template +class liner_base : private std::vector { + public: + liner_base() + : std::vector(std::numeric_limits::digits + 1, 0) {} + + bool insert(T w) { + for (int i = std::numeric_limits::digits; i >= 0; --i) { + if (!(w >> i)) continue; + + if (!this->at(i)) { + this->at(i) = w; + + return true; + } + + w ^= this->at(i); + } + + return false; + } +}; + +void dfs(int u, int f) { + vis[u] = true; + + for (auto e : g[u]) { + int v = e.first, + id = e.second; + + if (!vis[v]) { + dfs(v, u); + + s[u] ^= s[v]; + d[id] ^= s[v]; + } else if (v != f && !d[id]) { + d[id] = rng(); + + s[u] ^= d[id]; + s[v] ^= d[id]; + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1, u, v; i <= m; i++) { + cin >> u >> v; + + g[u].emplace_back(v, i); + g[v].emplace_back(u, i); + } + + dfs(1, 1); + + cin >> q; + + while (q--) { + int c; + liner_base lb; + bool ans = true; + + cin >> c; + + for (int i = 1, x; i <= c; i++) { + cin >> x; + + ans &= lb.insert(d[x]); + } + + cout << (ans ? "Connected" : "Disconnected") << endl; + } + + return 0; +}