【JZOJ 5239】 【GDOI2018模拟8.7】图的异或
2017-08-07 22:29
537 查看
Description
Solution
答案显然是统计所有的简单环,把它的异或值加线线性基,简单环则在dfs树上找返祖边,
最后统计线性基答案即可,
这里要用到线性基的性质:
把所有能组合出的数写出,
对于每一个二进制位,它要不一定为0,要不作为0出现的次数和作为1出现的次数相等,
所有用这个性质,直接统计答案即可。
复杂度:O(nlog(260))
Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fod(i,a,b) for(int i=a;i>=b;i--) #define efo(i,q) for(int i=A[q];i;i=B[i][0]) #define min(q,w) ((q)>(w)?(w):(q)) #define max(q,w) ((q)<(w)?(w):(q)) using namespace std; typedef long long LL; const int N=200500,mo=1e9+7; int read(int &n) { char ch=' ';int q=0,w=1; for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar()); if(ch=='-')w=-1,ch=getchar(); for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n; } int m,n,S,T; int a ; bool z ,OK; int B[2*N][2],A ,B0=1; LL Bv[2*N]; LL AL,ans; LL c[70],d ; LL er[70]; int JS; void link(int q,int w,LL e) { B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w,Bv[B0]=e; B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q,Bv[B0]=e; } void dfsf(int q,LL e) { JS++; if(JS%100000==0)printf("fefefe\n"); if(q==T)OK=1,AL=e; if(OK)return; z[q]=1; efo(i,q)if(!z[B[i][1]])dfsf(B[i][1],e^Bv[i]); } void ADD(LL q) { for(int i=1;q;i++)if(er[i]&q) if(c[i])q=q^c[i]; else {c[i]=q;break;} } void dfs(int q,int fai,LL e,int c) { z[q]=1;d[q]=e; efo(i,q) if((i^1)!=fai) { if(z[B[i][1]]) { ADD(e^d[B[i][1]]^Bv[i]); }else dfs(B[i][1],i,e^Bv[i],c+1); } } int main() { freopen("xor.in","r",stdin); freopen("xor.out","w",stdout); int q,w;LL e; er[1]=1;fo(i,2,62)er[i]=er[i-1]<<1; read(n),read(m); fo(i,1,m)read(q),read(w),scanf("%lld",&e),link(q,w,e); read(S),read(T); AL=0; dfsf(S,0); fo(i,1,n)z[i]=0; dfs(S,0,0,1); ans=0;q=0;LL t=0; fo(i,1,61)if(c[i])q++,t=t|c[i]; fo(i,1,61)if(t&er[i]) { ans=(ans+er[i]%mo*(er[q]%mo))%mo; }else if(AL&er[i])ans=(ans+er[i]%mo*(er[q+1]%mo))%mo; printf("%lld\n",ans); return 0; }
相关文章推荐
- 【jzoj5239】【GDOI2018模拟8.7】【图的异或】【线性基】
- [JZOJ5239]. 【GDOI2018模拟8.7】图的异或
- 【JZOJ5239】【GDOI2018模拟8.7】图的异或
- 【jzoj5237】【GDOI2018模拟8.7】【最长公共子序列 】【动态规划】
- 【GDOI2018模拟8.7】图的异或 线性基
- 【JZOJ5237】【GDOI2018模拟8.7】最长公共子序列
- 【JZOJ5238】【GDOI2018模拟8.7】的士碰撞
- 【jzoj5238】【GDOI2018模拟8.7】【的士碰撞】
- 【GDOI2018模拟8.7】图的异或
- JZOJ5239【GDOI模拟】图的异或
- 【JZOJ5222】【GDOI2018模拟7.12】A
- JZOJ5220. 【GDOI2018模拟7.10】C(2017.8DP&贪心专题)
- [JZOJ5261]【GDOI2018模拟8.12】求和
- 【JZOJ5262】【GDOI2018模拟8.12】树
- 【JZOJ5270】【GDOI2018模拟】神奇的矩阵(二维线段树)
- JZOJ 5221. 【GDOI2018模拟7.10】A
- 【JZOJ5224】【GDOI2018模拟7.12】C
- 【JZOJ5250】【GDOI2018模拟】质数(数论)
- 【jzoj5221】【GDOI2018模拟7.10】【A】【线段树合并】
- 【JZOJ5272】【GDOI2018模拟】神奇的重复序列(DP,性质题)