POJ 3764 The xor-longest Path trie树解决位运算贪心
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<cmath>
- #include<queue>
- using namespace std;
- const int maxn=;
- const double eps=1e-;
- const long long modn=;
- int n;
- int ans=;
- struct nod{
- int y;
- int next;
- int v;
- }e[maxn*];
- int head[maxn]={},tot=;
- int dis[maxn]={};
- struct tri{
- bool exist;
- int v;
- int next[];
- }a[maxn*];
- int tot1=;
- void init(int x,int y,int z){
- e[++tot].y=y;
- e[tot].v=z;
- e[tot].next=head[x];
- head[x]=tot;
- }
- void doit(int x,int v,int k){
- if(k<){
- a[x].exist=;
- a[x].v=v;
- return;
- }int z;
- if(v&(<<k)){
- z=;
- }else{
- z=;
- }
- if(!a[x].next[z]){
- a[x].next[z]=++tot1;
- }doit(a[x].next[z],v,k-);
- }
- void getit(int x,int v,int k){
- if(k<){
- int z=v^a[x].v;
- ans=max(ans,z);
- return;
- }int z;
- if(v&(<<k)){
- z=;
- }else{
- z=;
- }
- if(!a[x].next[z]){
- z=^z;
- }getit(a[x].next[z],v,k-);
- }
- void dfs(int x,int fa,int val){
- int y,v,z;
- for(int i=head[x];i;i=e[i].next){
- y=e[i].y;
- v=e[i].v;
- if(y!=fa){
- z=val^v;
- dis[y]=z;
- dfs(y,x,z);
- }
- }
- }
- void yu(){
- memset(a,,sizeof(a));
- memset(e,,sizeof(e));
- memset(head,,sizeof(head));
- tot1=tot=;
- memset(dis,,sizeof(dis));
- ans=;
- }
- int main(){
- while(~scanf("%d",&n)){
- yu();
- int x,y,z;
- for(int i=;i<n;i++){
- scanf("%d%d%d",&x,&y,&z);
- init(x+,y+,z);
- init(y+,x+,z);
- }
- dfs(,,);
- for(int i=;i<=n;i++){
- getit(,dis[i],);
- doit(,dis[i],);
- }
- printf("%d\n",ans);
- }
- return ;
- }
POJ 3764 The xor-longest Path trie树解决位运算贪心的更多相关文章
- Poj 3764 The xor-longest Path(Trie树+xor+贪心)
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6455 Accepted: 1392 ...
- 【POJ 3764】 The xor-longest path
[题目链接] http://poj.org/problem?id=3764 [算法] 首先,我们用Si表示从节点i到根的路径边权异或和 那么,根据异或的性质,我们知道节点u和节点v路径上的边权异或和就 ...
- 【bzoj1954】Pku3764 The xor-longest Path Trie树
题目描述 给定一棵n个点的带权树,求树上最长的异或和路径 输入 The input contains several test cases. The first line of each test ...
- POJ3764 The xor-longest path Trie树
代码写了不到30分钟,改它用了几个小时.先说题意,给你一颗树,边上有权,两点间的路径上的路径的边权抑或起来就是路径的xor值,要求的是最大的这样的路径是多少.讲到树上的两点的xor,一个常用的手段就是 ...
- HDU 4825 Xor Sum (trie树处理异或)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total S ...
- HDU4825 Xor Sum(字典树解决最大异或问题)
Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整 ...
- POJ-2777-CountColor(线段树,位运算)
链接:https://vjudge.net/problem/POJ-2777#author=0 题意: Chosen Problem Solving and Program design as an ...
- poj3764 The XOR Longest Path【dfs】【Trie树】
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10038 Accepted: ...
- 【POJ 3764】The Xor-longest Path
题目 给定一个\(n\)个点的带权无根树,求树上异或和最大的一条路径. \(n\le 10^5\) 分析 一个简单的例子 相信大家都做过这题: 给定一个\(n\)个点的带权无根树,有\(m\)个询问, ...
随机推荐
- 查询timestamp类型数据
$where=" roleid = 8 and lizhi = 0 and branchid IN (".implode(",",$ids).") a ...
- CodeForces - 1004B
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she ...
- 【洛谷 P3705】 [SDOI2017]新生舞会(费用流,01分数规划)
题目链接 看到这题我想到了以前做过的一题,名字记不清了,反正里面有"矩阵"二字,然后是道二分图匹配的题. 经典的行列连边网络流. 第\(i\)行和第\(j\)列连边,费用为\(b[ ...
- hdu 5328 Problem Killer(杭电多校赛第四场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 题目大意:找到连续的最长的等差数列or等比数列. 解题思路:1.等差等比的性质有很多.其中比较重 ...
- 一. Jmeter--使用代理录制脚本
Jmeter脚本是以.JMX格式为主 1. Jmeter也是支持录制的,支持第三方录制方式和代理录制方式. (1).第三方录制主要是通过badboy来录制,录制后另存为jmx格式即可. (2).Jme ...
- perl6正则 2: 字母,数字,空格,下划线, 字符集
数字, 字母, 下划线 在perl6中, 如果是 数字, 字母, 下划线, 在正则里可以正接写上. > so / True > so 'perl6_' ~~ /_/ True > 非 ...
- Ubuntu 17.10 用 apt 搭建 lamp 环境、安装 phpmyadmin、redis 服务+扩展、mysql 扩展、开启错误提示、配置虚拟主机
2018-02-24 13:50:30 更新: 个人喜欢相对原生又不太麻烦,所以用 apt 构建环境.不过,最近使用到现在记得出现过了 3 次 apache 或 mysql 服务器无法启动或无法连接的 ...
- bash: composer: command not found
下载composer到本地:curl -sS https://getcomposer.org/installer | php 移动至系统服务:sudo mv composer.phar /usr/bi ...
- 深度学习方法(八):自然语言处理中的Encoder-Decoder模型,基本Sequence to Sequence模型
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld.技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. Encoder-Decoder(编码- ...
- 使用BEEGO建立一个基本的API框架
用BEE API命令生成框架. 然后自行更改MODELS,加入MYSQL支持ORM. 然后,自定义了字段的对应,表的名称等. 参考URL: http://www.cnblogs.com/studyzy ...