#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("-O3")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("fast-math")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
void umin(int &a,int b){a=min(a,b);}
void umax(int &a,int b){a=max(a,b);}
bool is_prime(ll val){for(ll i=2;i<=sqrt(val);i++)if(val%i==0)return 0; return 1;}
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll tx[4]={0,1,-1,1};
const ll ty[4]={-1,0,1,1};
const char rev_to[4]={'E','W','N','S'};
const int M=1e9;
const int N=2e5+2;
const int ppp=73;
const int lg=19;
const int OPEN=1;
const int CLOSE=0;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> st;
auto rnd=bind(uniform_int_distribution<ll>(1,N),mt19937(time(0)));
void bad(){
cout<<"NE";
exit(0);
}
vector<pii>g[N];
int n,m;
vector<pair<int,pii>>edges;
int v,u,x;
int p[N],s[N];
void init(){iota(p,p+N,0);fill(s,s+N,1);}
int dad(int v) {if(v==p[v]) return v; return p[v]=dad(p[v]);}
bool mg(int a,int b){
int ra=dad(a),rb=dad(b);
if(ra==rb) return 0;
if(s[ra]<s[rb])swap(ra,rb);
p[rb]=ra;s[ra]+=s[rb];
return 1;
}
const int K=32;
int basis[K];
vector<int>lol[N];
int wh[N],inv[N];
int sz;
void add(int msk,int nmb){
for(int i=0;i<K;i++){
if(!(pw(i) &msk)) continue;
if(!basis[i]){
basis[i]=msk;
wh[sz]=i;inv[i]=sz;
sz++;
return;
}
msk^=basis[i];
}
}
void to_conclude(int val,int nmb){
for(int i=0;i<K;i++){
if(!(pw(i) &val)) continue;
lol[inv[i]].p_b(nmb);
val^=basis[i];
}
}
int xr[N];
int V[N],U[N],X[N];
void dfs(int v,int xx,int p){
xr[v]=xx;
for(auto &z : g[v]){
if(z.f==p) continue;
dfs(z.f,z.s^xx,v);
}
}
signed main()
{
// freopen("in.txt","r",stdin);
fast_io;
cin>>n>>m;
init();
vector<int>nd;
for(int i=0;i<m;i++){
cin>>V[i]>>U[i]>>X[i];V[i]--;U[i]--;
int x1=dad(V[i]),x2=dad(U[i]);
if(x1==x2){
nd.p_b(i);
}else {
mg(x1,x2);
g[V[i]].p_b({U[i],X[i]});
g[U[i]].p_b({V[i],X[i]});
}
}
dfs(0,0,0);
int cnt=0;
for(auto &z : nd){
int lulw=xr[V[z]]^xr[U[z]]^X[z];
if(!lulw) continue;
add(lulw,z);
cnt++;
}
if(!cnt) cout<<0;
else{
cout<<sz<<endl;
for(auto &z : nd){
int lulw=xr[V[z]]^xr[U[z]]^X[z];
if(!lulw) continue;
to_conclude(lulw,z);
}
for(int i=0;i<sz;i++){
cout<<basis[wh[i]]<<' ';
cout<<sz(lol[i])<<' ';
for(auto &z : lol[i]) cout<<z+1<<' ';
cout<<endl;
}
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
14200 KB |
Output is correct |
2 |
Correct |
43 ms |
14712 KB |
Output is correct |
3 |
Correct |
14 ms |
11904 KB |
Output is correct |
4 |
Correct |
13 ms |
12032 KB |
Output is correct |
5 |
Correct |
89 ms |
19960 KB |
Output is correct |
6 |
Correct |
92 ms |
19832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
12536 KB |
Output is correct |
2 |
Correct |
19 ms |
12544 KB |
Output is correct |
3 |
Correct |
27 ms |
13304 KB |
Output is correct |
4 |
Correct |
26 ms |
13568 KB |
Output is correct |
5 |
Correct |
60 ms |
16888 KB |
Output is correct |
6 |
Correct |
36 ms |
14712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
15480 KB |
Output is correct |
2 |
Correct |
59 ms |
17036 KB |
Output is correct |
3 |
Correct |
7 ms |
11264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
17528 KB |
Output is correct |
2 |
Correct |
106 ms |
21108 KB |
Output is correct |
3 |
Correct |
8 ms |
11520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
16120 KB |
Output is correct |
2 |
Correct |
64 ms |
17532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
18168 KB |
Output is correct |
2 |
Correct |
41 ms |
15456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
18464 KB |
Output is correct |
2 |
Correct |
92 ms |
20468 KB |
Output is correct |
3 |
Correct |
63 ms |
17272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
21240 KB |
Output is correct |
2 |
Correct |
130 ms |
23028 KB |
Output is correct |
3 |
Correct |
121 ms |
22644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
13816 KB |
Output is correct |
2 |
Correct |
38 ms |
14464 KB |
Output is correct |
3 |
Correct |
77 ms |
18808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
19320 KB |
Output is correct |
2 |
Correct |
50 ms |
16120 KB |
Output is correct |
3 |
Correct |
103 ms |
21620 KB |
Output is correct |