题意:http://www.lydsy.com/JudgeOnline/problem.php?id=2115

sol  :首先考虑处理出DFS树,那么树上的所有非树边可以构成一个简单环

   因为所有不在1-n的路径上的树边都会被走过去再走回来,对答案无法构成影响

   所以答案即为1-n路径的异或和^(所有环的异或和任选)的最大值

   那么问题转化为从k个数中任选使其异或一个特定的数得异或和最大

   直接跑线性基即可

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
const int Mx=;
int n,m,cnt,ans,now,tmp,val[Mx],cir[Mx],vis[Mx];
int tot,head[Mx],nxt[Mx],ver[Mx],cost[Mx];
void add(int x,int y,int z)
{
nxt[++tot]=head[x];
ver[tot]=y;
cost[tot]=z;
head[x]=tot;
}
void dfs(int x)
{
vis[x]=;
for(int i=head[x];i;i=nxt[i])
{
int y=ver[i];
if(!vis[y])
val[y]=val[x]^cost[i],dfs(y);
else
cir[++cnt]=val[x]^val[y]^cost[i];
}
}
void gauss()
{
now=,m=;
while(m--)
{
tmp=; for(int j=now;j<=cnt;j++) if((cir[j]>>m)&) { tmp=j;break; }
if(tmp)
{
swap(cir[tmp],cir[now]);
for(int j=;j<=cnt;j++) if(j!=now&&((cir[j]>>m)&)) cir[j]^=cir[now];
now++;
}
}
}
signed main()
{
scanf("%lld%lld",&n,&m);
for(int i=,x,y,z;i<=m;i++)
{
scanf("%lld%lld%lld",&x,&y,&z);
add(x,y,z),add(y,x,z);
}
dfs(); gauss(); ans=val[n];
for(int i=;i<now;i++) ans=max(ans,ans^cir[i]);
cout<<ans<<endl;
return ;
}

最新文章

  1. 让ASP.NET5在Jexus上飞呀飞
  2. 关于SQL的相关笔记【长期更新,只发一帖】
  3. MVC项目实践,在三层架构下实现SportsStore-06,实现购物车
  4. 前端自动化工具:Grunt使用教程
  5. 【转】statfs获得硬盘使用情况 模拟linux命令 df
  6. CentOS 下SSH无密码登录的配置
  7. php常用系统函数
  8. frameset标签代码实现网站跳转
  9. 数据结构(莫队算法):HH的项链
  10. 善用VS中的Code Snippet来提高开发效率 分类: C# 2015-01-22 11:06 69人阅读 评论(0) 收藏
  11. Debain 7.2安装配置
  12. nand驱动移植
  13. C#设计模式(1)-单例模式
  14. Redis连接出现Error: Connection reset by peer的问题是由于使用Redis的安全模式
  15. 【Spark-core学习之七】 Spark广播变量、累加器
  16. LeetCode刷题 fIRST MISSING POSITIVE
  17. Linux下NTP服务器配置
  18. Apache 服务器 基础知识小结
  19. FIND_IN_SET()函数
  20. 微信小程序 - 分包加载(分包使用)

热门文章

  1. 简单ssh
  2. Win8如何默认以管理员运行程序
  3. Java 批量文件压缩导出,并下载到本地
  4. EasyUI取消树节点选中
  5. 最常用且非常重要的Linux命令
  6. Linux系统kernel参数优化
  7. 详解 JS 中 new 调用函数原理
  8. tp3.2框架中使用volist输出混乱的一点发现
  9. JZOJ 4735. 最小圈
  10. Java总结 - List实现类ArrayList&amp;LinkedList