BZOJ 2115: [Wc2011] Xor 线性基 dfs
2024-10-11 22:10:41
https://www.lydsy.com/JudgeOnline/problem.php?id=2115
每一条从1到n的道路都可以表示为一条从1到n的道路异或若干个环的异或值。
那么把全部的环丢到线性基里基本操作就可以了。。
https://blog.csdn.net/qaq__qaq/article/details/53812883 这个博客非常好
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define LL long long
const int maxn=;
int n,m;
struct nod{
int y,next;LL v;
}e[maxn*];
int head[maxn]={},tot=;
LL b[]={},c[]={},d[maxn]={},val[maxn*]={},cnt=,tem=;
bool vis[maxn]={};
void init(int x,int y,LL v){
e[++tot].y=y;e[tot].v=v;e[tot].next=head[x];head[x]=tot;
}
void dfs(int x){
vis[x]=;
for(int i=head[x];i;i=e[i].next){
if(!vis[e[i].y]){
d[e[i].y]=d[x]^e[i].v;
dfs(e[i].y);
}
else val[++cnt]=d[e[i].y]^d[x]^e[i].v;
}
}
void getit(LL x){
for(int i=;i>;i--){
if(x&c[i]){
if(!b[i]){b[i]=x;break;}
x^=b[i];
}
}
}
int main(){
int x,y;LL z;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d%d%lld",&x,&y,&z);
init(x,y,z);init(y,x,z);
}
dfs();c[]=;
for(int i=;i<=;i++)c[i]=c[i-]*;
for(int i=;i<=cnt;i++){getit(val[i]);}
LL ans=d[n];
for(int i=;i>;i--)ans=max(ans,ans^b[i]);
printf("%lld\n",ans);
return ;
}
最新文章
- 我的第一篇博客/markdown
- tp框架总结(四)
- shellinabox基于web浏览器的终端模拟器
- Windows Server 2012 R2下通过80端口访问Odoo ERP
- 设置MyEclipse开发项目时使用的JDK
- Android手机指令操作释疑
- DevExpress - cxGrid 使用方法
- Java学习路线图&#183;影响一代又一代程序员的经典书籍!(转)
- POJ 2976 Dropping tests(二分答案)
- Flex中的FusionCharts 2D柱形图
- python之路(11)描述符
- 鼠标右键添加Sublime Text
- Error:java: Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [web_dao,web_service] are excluded from annotation processing
- C++ 保存Excel文件(带密码保护)
- Python学习(23):Python面向对象(1)速成
- 科学计算三维可视化---Mlab基础(改变物体的外观颜色)
- 虚拟机VMware搭建代码环境
- opencv——阈值分割图像
- 使用kubeadm安装kubernetes1.12.1
- 使用HelpProvide组件调用帮助文件