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 namespace std;
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005
#define LOGN 30
vector<array<int, 3>> adj[N];
int dist[N], vis[N], mark[N], val[N], base[N];
void dfs(int node, int root, int d){
dist[node] = d;
vis[node] = 1;
for (auto i : adj[node]){
int curr = i[0], w = i[1], ind = i[2];
if (curr == root) continue;
if (vis[curr]){
mark[ind] = 1;
val[ind] = w ^ dist[curr] ^ dist[node];
}
else{
dfs(curr, node, d ^ w);
}
}
}
int32_t main(){
#ifndef ONLINE_JUDGE
//fileio();
#endif
fastio();
int n, m;
cin>>n>>m;
for (int i = 1; i <= m; i++){
int u, v, w;
cin>>u>>v>>w;
adj[u].pb({v, w, i});
adj[v].pb({u, w, i});
}
dfs(1, 0, 0);
for (int i = 1; i <= m; i++){
if (mark[i]){
int x = val[i];
for (int j = LOGN; j >= 0; j--){
if (x & (1<<j)){
if (base[j] != 0){
x ^= base[j];
}
else{
base[j] = x;
break;
}
}
}
}
}
vector<int> ans[LOGN + 1];
for (int i = 1; i <= m; i++){
if (mark[i]){
int x = val[i];
for (int j = LOGN; j >= 0; j--){
if (x & (1<<j)){
ans[j].pb(i);
x ^= base[j];
}
}
}
}
int res = 0;
for (int i = LOGN; i >= 0; i--){
if (ans[i].size()) res++;
}
cout<<res<<endl;
for (int i = LOGN; i >= 0; i--){
if (ans[i].size()){
cout<<base[i]<<sp<<ans[i].size()<<sp;
for (auto j : ans[i])
cout<<j<<sp;
cout<<endl;
}
}
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# | 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... |