mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-09 16:58:48 +00:00
parent
faf4f402e7
commit
2600cf97f9
109
S2OJ/1905/1905.cpp
Normal file
109
S2OJ/1905/1905.cpp
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
T query_min(T w) {
|
||||||
|
for (int i = std::numeric_limits<T>::digits; i >= 0; --i) {
|
||||||
|
if (!((w >> i) & 1)) continue;
|
||||||
|
|
||||||
|
w ^= this->at(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
BIN
S2OJ/1905/data/connect1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect11.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect12.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect13.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect14.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect15.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect16.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect17.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect18.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect19.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect20.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/connect9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/connect9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/std.cpp
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/std.cpp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1905/data/val.cpp
(Stored with Git LFS)
Normal file
BIN
S2OJ/1905/data/val.cpp
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user