http://poj.org/problem?id=3764 题意 :  一颗树,每个边有个值,在树上找一条简单路径,使得这条路径上的边权异或值最大 先找到所有节点到一点的距离 , 显然dis( x , y ) = dis( z , x )^dis( z , y ) 那么把所有的距离都以二进制由高到低存到trie中 , 扫一遍每个点 , 在trie树上由高到低找某位与该点某位相反的数 , 找不到则妥协找下一位 , 如此贪心即可  写的时候超空间一次re两次,trie树的大小设置为30*n刚好,不…
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6455 Accepted: 1392 Description In an edge-weighted tree, the xor-length of a path p is defined as the xor sum of the weights of edges on p: {xor}length(p)=\oplus{e \in p…
[题目链接] http://poj.org/problem?id=3764 [算法] 首先,我们用Si表示从节点i到根的路径边权异或和 那么,根据异或的性质,我们知道节点u和节点v路径上的边权异或和就是Sx xor Sy 问题就转化为了 : 在若干个数中,找到两个数异或的最大值,可以用Trie树加速,具体细节笔者不再赘述 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <…
题目描述  给定一棵n个点的带权树,求树上最长的异或和路径 输入 The input contains several test cases. The first line of each test case contains an integer n(1<=n<=100000), The following n-1 lines each contains three integers u(0 <= u < n),v(0 <= v < n),w(0 <= w &l…
代码写了不到30分钟,改它用了几个小时.先说题意,给你一颗树,边上有权,两点间的路径上的路径的边权抑或起来就是路径的xor值,要求的是最大的这样的路径是多少.讲到树上的两点的xor,一个常用的手段就是随便选一个根,然后深搜记下每个点v到根的xor路径 w[v],那么两点x,y路径的xor就是w[x]^w[y]. 深搜一发,问题转化为给你一个数组a,求a中哪两个数的抑或值最大.解决该问题的方法就是Trie树. 对每个权值由二进制高位到低位插到Trie树里,当要询问对于权值x最大的xor的时候,就需…
Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 3647    Accepted Submission(s): 1595 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Ze…
Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大.Prometheus 为了让 Zeus 看到人类的伟大,随即同意 Zeus 可以向人类求助.你能证明人类的智慧么?  Input输入包含若干组测试数据,每组测试数据包含若干行. 输入的第一行是一个整数T(…
链接:https://vjudge.net/problem/POJ-2777#author=0 题意: Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with length L centimeter, L i…
The xor-longest Path Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10038   Accepted: 2040 Description In an edge-weighted tree, the xor-length of a path p is defined as the xor sum of the weights of edges on p: ⊕ is the xor operator. W…
题目 给定一个\(n\)个点的带权无根树,求树上异或和最大的一条路径. \(n\le 10^5\) 分析 一个简单的例子 相信大家都做过这题: 给定一个\(n\)个点的带权无根树,有\(m\)个询问,要求树上两点之间的权值异或和. \(n,m\le 10^7\) Xor运算有一些很显然的性质: \(a \oplus a = 0\) \(a \oplus b = b \oplus a\) \(a\oplus b\oplus c = a\oplus(b\oplus c)\) 对于这道水题,我们只需要…