G-xor-matic number of the Graph
The enhanced version of the previous question requires a bitwise contribution for each unicom block.
#include <bits/stdc++.h>#defineLL Long Long#defineFi first#defineSe Second#defineMk Make_pair#definePII Pair<int, int>#definePLI Pair<ll, int>#defineull unsigned long Longusing namespacestd;Const intN = 1e5 +7;Const intINF =0x3f3f3f3f;ConstLL INF =0x3f3f3f3f3f3f3f3f;Const intMoD = 1e9 +7;intN, M; LL D[n], bin[n], num[2];BOOLVis[n];vector<PLI>Edge[n];vector<int>ID;structBase {LL a[ the]; intCNT; voidinit () {memset (A,0,sizeof(a)); CNT=0; } voidAdd (LL x) { for(intj = +; ~j; j--) { if((x >> J) &1) { if(!a[j]) {a[j]=x; cnt++; Break;} ElseX ^=A[j]; } } }} Base;voidDfsintUintFA) {Vis[u]=true; Id.push_back (U); for(inti =0; I < edge[u].size (); i++) { intv = edge[u][i].se; LL W =edge[u][i].fi; if(v = = FA)Continue; if(Vis[v]) {Base. Add (d[u]^d[v]^W); } Else{D[v]= D[u] ^W; DFS (v, u); } }}intMain () {Base. Pirnt (); scanf ("%d%d", &n, &m); for(inti=bin[0]=1; I <= N; i++) Bin[i]= bin[i-1] *2%MoD; for(inti =1; I <= m; i++) { intu, v; LL W; scanf ("%d%d%lld", &u, &v, &W); Edge[u].push_back (Mk (W, v)); Edge[v].push_back (Mk (W, u)); } LL ans=0; for(inti =1; I <= N; i++) { if(!Vis[i]) { Base. Init (); Id.clear (); DFS (i,0); for(intj =0; J <= +; J + +) {num[0] =0, num[1] =0; for(Auto &x:id) {num[(d[x]>>J) &1]++; } BOOLFlag =false; for(intK =0; K < the; k++) { if((Base. A[k]>>j) &1) {flag=true; Break; }} LL tmp= num[0]* (num[0]-1)/2+ num[1]* (num[1]-1)/2; TMP%=MoD; if(flag) ans = (ans + bin[j]*bin[Base. cnt-1]%MOD*TMP%MOD)%MoD; TMP= num[0] * num[1] %MoD; if(flag) ans = (ans + bin[j]*bin[Base. cnt-1]%MOD*TMP%MOD)%MoD; ElseAns = (ans + bin[j]*bin[Base. Cnt]%mod*tmp%mod)%MoD; }}} printf ("%lld\n", ans); return 0;}/**/
Intel Code Challenge Final Round (div. 1 + div. 2, Combined) g-xor-matic number of the Graph linear base good question