이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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] and accum[u] != accum[v]) {
change.emplace_back(e, accum[u] ^ accum[v]);
}
}
})(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... |