0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:28:47 +00:00

P5227 [AHOI2013]连通图

https://www.luogu.com.cn/record/101799398
This commit is contained in:
Baoshuo Ren 2023-02-09 21:48:44 +08:00
parent 2600cf97f9
commit c90f705060
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

99
Luogu/P5227/P5227.cpp Normal file
View File

@ -0,0 +1,99 @@
#include <iostream>
#include <algorithm>
#include <iterator>
#include <limits>
#include <random>
#include <utility>
#include <vector>
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<std::pair<int, int>> g[N];
bool vis[N];
template <typename T>
class liner_base : private std::vector<T> {
public:
liner_base()
: std::vector<T>(std::numeric_limits<T>::digits + 1, 0) {}
bool insert(T w) {
for (int i = std::numeric_limits<T>::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<int> 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;
}