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 ;
}

最新文章

  1. 我的第一篇博客/markdown
  2. tp框架总结(四)
  3. shellinabox基于web浏览器的终端模拟器
  4. Windows Server 2012 R2下通过80端口访问Odoo ERP
  5. 设置MyEclipse开发项目时使用的JDK
  6. Android手机指令操作释疑
  7. DevExpress - cxGrid 使用方法
  8. Java学习路线图&#183;影响一代又一代程序员的经典书籍!(转)
  9. POJ 2976 Dropping tests(二分答案)
  10. Flex中的FusionCharts 2D柱形图
  11. python之路(11)描述符
  12. 鼠标右键添加Sublime Text
  13. 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
  14. C++ 保存Excel文件(带密码保护)
  15. Python学习(23):Python面向对象(1)速成
  16. 科学计算三维可视化---Mlab基础(改变物体的外观颜色)
  17. 虚拟机VMware搭建代码环境
  18. opencv——阈值分割图像
  19. 使用kubeadm安装kubernetes1.12.1
  20. 使用HelpProvide组件调用帮助文件

热门文章

  1. D - Balanced Ternary String (贪心)
  2. Strusts2笔记5--数据验证
  3. CentOS安装ANT
  4. 曹冲称象小游戏pygame实现
  5. qt使用动态库(DLL)
  6. 12 Release History for go go语言的版本历史
  7. Mac上删除不了的文件,Windows上也粉碎不了怎么办?
  8. MongoDB安全:所有操作(Privilege Actions)
  9. align=&quot;absmiddle&quot; 的意义
  10. python dict交换key value值