This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
template <class F> struct RecLambda : private F {
explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
template <class... Args> decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
vector<int> C(M);
vector<vector<pair<int, int>>> graph(N);
for (int i = 0; i < M; ++i) {
int a, b;
std::cin >> a >> b >> C[i];
a -= 1, b -= 1;
graph[a].emplace_back(b, i);
graph[b].emplace_back(a, i);
}
vector<int> accum(N), depth(N, -1);
depth[0] = 0;
vector<pair<int, int>> change;
RecLambda([&](auto&& dfs, const int u, const int p) -> void {
for (const auto& [v, e] : graph[u]) {
if (v == p) continue;
if (depth[v] == -1) {
accum[v] = accum[u] ^ C[e];
depth[v] = depth[u] + 1;
dfs(v, u);
} else if (depth[u] > depth[v]) {
const int x = C[e] ^ accum[u] ^ accum[v];
if (x != 0) {
change.emplace_back(e, x);
}
}
}
})(0, 0);
vector<int> base;
for (const auto& [e, v] : change) {
int x = v;
for (const int b : base) {
if (x > (x ^ b)) {
x ^= b;
}
}
if (x != 0) {
base.push_back(x);
}
}
std::cout << base.size() << '\n';
for (const int b : base) {
vector<int> apply;
for (auto& [e, v] : change) {
if (v > (v ^ b)) {
v ^= b;
apply.push_back(e);
}
}
std::cout << b << ' ' << apply.size();
std::sort(apply.begin(), apply.end());
for (const int e : apply) {
std::cout << ' ' << e + 1;
}
std::cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |