异或值 xor
题目描述
给出一个 N 个点的带权无向图,要求从 1 号点到 N 号点的一条路径,使得路径上的边 权异或值最大.
输入格式
第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目。
接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边。 图中可能有重边或自环。
输出格式
仅包含一个整数,表示最大的XOR和(十进制结果) 。
样例
样例输入
5 7
1 2 2
1 3 2
2 4 1
2 5 1
4 5 3
5 3 4
4 3 2
样例输出
6
数据范围与提示

【题目来源】
WC2011
solution
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
#define ll long long
using namespace std;
int n,m,head[maxn],tot=,top;
ll t3,c[maxn*],d[maxn],b[];
bool vis[maxn];
struct node{
int v,nex;
ll w;
}e[maxn*];
void lj(int t1,int t2,ll t3){
e[++tot].v=t2;e[tot].w=t3;e[tot].nex=head[t1];head[t1]=tot;
}
void dfs(int k,ll v){
vis[k]=;d[k]=v; for(int i=head[k];i;i=e[i].nex){
if(!vis[e[i].v]){
dfs(e[i].v,v^e[i].w);
}
else c[++top]=v^d[e[i].v]^e[i].w;
}
}
int main()
{
cin>>n>>m;
for(int i=,t1,t2;i<=m;i++){
scanf("%d%d%lld",&t1,&t2,&t3);
lj(t1,t2,t3);lj(t2,t1,t3);
}
dfs(,); for(int i=;i<=top;i++){
for(int j=;j>=;j--){
if(c[i]&(1LL<<j)){
if(!b[j]){b[j]=c[i];break;}
else c[i]^=b[j];
}
}
}
ll ans=d[n];
for(int i=;i>=;i--){
ans=max(ans,ans^b[i]);
}
cout<<ans<<endl;
return ;
}
异或值 xor的更多相关文章
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- Codeforces Round #482 (Div. 2) : Kuro and GCD and XOR and SUM (寻找最大异或值)
题目链接:http://codeforces.com/contest/979/problem/D 参考大神博客:https://www.cnblogs.com/kickit/p/9046953.htm ...
- 51Nod XOR key —— 区间最大异或值 可持久化字典树
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1295 1295 XOR key 题目来源: HackerRa ...
- [LeetCode] 421. Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- LeetCode 421. 数组中两个数的最大异或值(Maximum XOR of Two Numbers in an Array) 71
421. 数组中两个数的最大异或值 421. Maximum XOR of Two Numbers in an Array 题目描述 给定一个非空数组,数组中元素为 a0, a1, a2, - , a ...
- 异或链表(XOR linked list)
异或链表(Xor Linked List)也是一种链式存储结构,它可以降低空间复杂度达到和双向链表一样目的,任何一个节点可以方便的访问它的前驱节点和后继结点.可以参阅wiki 普通的双向链表 clas ...
- 【机器学习】神经网络实现异或(XOR)
注:在吴恩达老师讲的[机器学习]课程中,最开始介绍神经网络的应用时就介绍了含有一个隐藏层的神经网络可以解决异或问题,而这是单层神经网络(也叫感知机)做不到了,当时就觉得非常神奇,之后就一直打算自己实现 ...
- Leetcode 421.数组中两数的最大异或值
数组中两数的最大异或值 给定一个非空数组,数组中元素为 a0, a1, a2, … , an-1,其中 0 ≤ ai < 231 . 找到 ai 和aj 最大的异或 (XOR) 运算结果,其中0 ...
- Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数
E. Beautiful Subarrays One day, ZS the Coder wrote down an array of integers a with elements a1, ...
随机推荐
- 全文检索(Lucene&Solr)
全文检索(Lucene&Solr) 1)什么是全文检索?为什么需要全文检索? 结构化数据(mysql等)方便查询,而非结构化数据(如多篇文章)是难以查询到自己需要的,所以要使用全文检索. 全文 ...
- js对象动态添加属性,方法
1. 动态添加属性,方法 var object = new Object(); object.name = "name"; object.age = 19; >>> ...
- Zeppelin interperter 模式设置总结图解1
如有错漏,望请指正,不胜感激. 参考:[zeppelin官网]:https://zeppelin.apache.org/docs/latest/interpreter/spark.html#inter ...
- css样式 body的font-size 为什么用625%
浏览器的默认高度?一般为16px. 为什么用62.5%作为body的默认样式?16px62.5%=10px.* 那么为什么一般多是 16px *625% = 100px; <响应式Web设计实 ...
- ethereum(以太坊)(五)--Bool
pragma solidity ^0.4.0; contract Bool{ uint num1 = 100; uint num2 = 200; bool _c = true; // &&am ...
- linux-shell——02
Linux命令的通用命令格式 :命令字 [选项] [参数] 选项: 作用:用于调节命令的具体功能 "-"引导短格式选项(单个字符) EX:“-l” "--"引导 ...
- C# 创建新线程
首先需要包含命名空间 using System.Threading; 然后创建进程 Thread th = new Thread(new ThreadStart(ThreadMethod)); //创 ...
- 1、spring boot入门
1.Spring Boot 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案: 2.微服务 2014,martin fowler 微服务: ...
- 第一章:Hello, World!
感谢作者 –> 原文链接 本文翻译自The Flask Mega-Tutorial Part I: Hello, World! 一趟愉快的学习之旅即将开始,跟随它你将学会用Python和Flas ...
- 【UE4】二十三、UE4笔试面试题
在CSDN博客看到的,带着这些问题,多多留意,正所谓带着问题学习. 一. 1.Actor的EndPlay事件在哪些时候会调用? 2.BlueprintImplementableEvent和Bluepr ...