This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author win11905
*/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define long long long
#define pii pair<int, int>
#define iii tuple<int, int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e5+5;
class prakticni {
private:
int n, m;
int s[N], t[N], w[N], d[N], cyc[N];
vector<int> vec, g[N];
bool check[N];
void dfs(int u, int p) {
check[u] = true;
for(int x : g[u]) {
int v = u ^ s[x] ^ t[x];
if(v == p) continue;
if(check[v]) vec.emplace_back(x);
else d[v] = d[u] ^ w[x], dfs(v, u);
}
}
public:
void solve(istream& cin, ostream& cout) {
cin >> n >> m;
for(int i = 1; i <= m; ++i) {
cin >> s[i] >> t[i] >> w[i];
g[s[i]].emplace_back(i);
g[t[i]].emplace_back(i);
}
dfs(1, 0);
for(int e : vec) cyc[e] = d[s[e]] ^ d[t[e]] ^ w[e];
vector<pair<int, vector<int> > > ans;
for(int i = 0; i < 30; ++i) {
int val = 0;
for(int v : vec) if(cyc[v] >> i & 1) val = cyc[v];
if(!val) continue;
vector<int> ret;
for(int v : vec) if(cyc[v] >> i & 1) {
ret.emplace_back(v);
cyc[v] ^= val;
}
ans.emplace_back(val, ret);
}
cout << ans.size() << endl;
for(auto z : ans) {
cout << z.x << ' ' << z.y.size() << ' ';
for(int v : z.y) cout << v << ' ';
cout << endl;
}
}
};
class Solver {
public:
void solve(std::istream& in, std::ostream& out) {
prakticni *obj = new prakticni();
obj->solve(in, out);
}
};
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
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... |