[高斯消元 线性基] BZOJ 2115 [Wc2011] Xor
来源:互联网 发布:王珊数据库自学材料 编辑:程序博客网 时间:2024/06/06 00:11
任意两条路径的和为一个环
任取一条1-N的路,找一个环与其XOR和最大
莫队 Orz
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;typedef long long ll;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}inline void read(ll &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=50005,M=100005;struct edge{ int u,v,next; ll w;}G[M<<1];int head[N],inum;inline void add(int u,int v,ll w,int p){ G[p].u=u; G[p].v=v; G[p].w=w; G[p].next=head[u]; head[u]=p;}int n,m,tot;ll depth[N];int vst[N];ll a[M<<1];#define V G[p].vinline void dfs(int u,int fa){ vst[u]=1; for (int p=head[u];p;p=G[p].next) if (p!=(fa^1)) { if (!vst[V]) depth[V]=depth[u]^G[p].w,dfs(V,p); else a[++tot]=depth[V]^depth[u]^G[p].w; }}inline int Gauss(){ int k=1; for (int p=63;~p;p--) { int t=0; for (int i=k;i<=tot && !t;i++) if (a[i]>>p&1) t=i; if (!t) continue; swap(a[t],a[k]); for (int i=1;i<=tot;i++) if (i!=k && a[i]>>p&1) a[i]^=a[k]; k++; } return k--;}int main(){ int iu,iv; ll iw; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(m); for (int i=1;i<=m;i++) read(iu),read(iv),read(iw),add(iu,iv,iw,++inum),add(iv,iu,iw,++inum); dfs(1,0); tot=Gauss(); ll ans=depth[n]; for (int i=1;i<=tot;i++) if ((ans^a[i])>ans) ans^=a[i]; printf("%lld\n",ans); return 0;}
0 0
- [高斯消元 线性基] BZOJ 2115 [Wc2011] Xor
- BZOJ 2115([Wc2011] Xor-线性基求法)
- BZOJ 2115 WC2011 Xor 线性基+贪心
- 【BZOJ 2115】[Wc2011] Xor 线性基
- [BZOJ 2115][Wc2011] Xor:线性基
- BZOJ 2115: [Wc2011] Xor 线性基
- BZOJ 2115 [Wc2011] Xor 线性基+图论
- [BZOJ 2115 Wc2011 Xor]线性基
- bzoj 2115: [Wc2011] Xor (高斯消元求解线性基)
- 2115: [Wc2011] Xor 线性基
- bzoj 2115: [Wc2011] Xor 线性基+dfs树
- bzoj 2115: [Wc2011] Xor(DFS+线性基)
- 【BZOJ】【P2115】【Wc2011】【Xor】【题解】【线性基】
- BZOJ 2115 [Wc2011] Xor 高斯消元
- 【BZOJ 2115】 [Wc2011] Xor
- BZOJ-2115-Xor-WC2011
- 【bzoj 2115】: [Wc2011] Xor
- BZOJ 2115 [Wc2011] Xor
- 使用Picasso加载图片
- openstack kilo版中的配额管理quota
- jslint to eslint
- 自己实现的简易版printf
- Android 在一个程序中启动另一个程序
- [高斯消元 线性基] BZOJ 2115 [Wc2011] Xor
- 抽象工厂模式
- 正则表达式 电话 手机号 邮箱 日期 金额
- angularjs中ng-show和css中display的区别
- 关于TCP和UDP的端口介绍
- 深入理解JavaScript系列之设计模式
- 【Tween Animation 变化动画】
- PHP文件上传后缀名与文件类型对照表
- 使用ping++进行微信公众号支付