POJ - 3764 - The xor-longest Path ( 01字典树 + 异或前缀和 )

保姆级教程:用CANoe手把手复现ECU刷写全流程(含BootLoader三阶段详解) 本文提供了一份详细的CANoe ECU刷写实战指南,涵盖BootLoader三阶段的深度解析。从实验环境搭建到预编程、主编程及后编程阶段,逐步讲解ECU刷写的关键步骤和隐藏逻辑,特别强调UDS诊断和CAN通信的精确控制,帮助开发者掌握ECU刷写的核心技术。 阅读详情
题目链接:点击进入
题目

在这里插入图片描述
在这里插入图片描述

题意

找出树上任意不同两点间最大的路径边权的异或值。

思路

假设 sum [ x ] 表示根节点到 x 路径上所有边权的 xor 值,显然有:
sum [ x ] = sum [ father ( x ) ] xor weight ( x , father ( x ) )
根据上式,我们可以对树进行一次深度优先遍历,求出所有的 sum [ x ] 。不难发现,树上 x 到 y 的路径上所有边权的 xor 结果就等于 sum [ x ] xor sum [ y ] 。这是因为根据 xor 运算的性质 ( a xor a = 0 ) , " x 到根 " 和 " y 到根 " 这两条路径重叠的部分恰好抵消掉。
所以,问题就变成了从 sum [ 0 ] ~ sum [ n - 1 ] 这 n 个数中选出两个,xor 结果最大,即。可以用 trie 树来快速求解。

代码
// Problem: The xor-longest Path
// Contest: Virtual Judge - POJ
// URL: https://vjudge.net/problem/POJ-3764
// Memory Limit: 65 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize(3)//O3
//#pragma GCC optimize(2)//O2
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
//#define int long long
//#define double long double
//#define rep(i,x,y) for(register int i = x; i <= y;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const int maxn=1e5+10;
const int mod=998244353;
const double eps=1e-9;
const int N=5e3+10;
/*--------------------------------------------*/
inline int read()
{
    int k = 0, f = 1 ;
    char c = getchar() ;
    while(!isdigit(c)){if(c == '-') f = -1 ;c = getchar() ;}
    while(isdigit(c)) k = (k << 1) + (k << 3) + c - 48 ,c = getchar() ;
    return k * f ;
}
/*--------------------------------------------*/

int n,sum[maxn];
int head[maxn<<1],cnt;
struct node
{
	int w;
	int to;
	int next;
}edge[maxn<<1];
void add(int u,int v,int w)
{
	edge[cnt].to=v;
	edge[cnt].w=w;
	edge[cnt].next=head[u];
	head[u]=cnt++;
}
void dfs(int pos,int fa)
{
	for(int i=head[pos];i!=-1;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==fa) continue;
		sum[v]=sum[pos]^edge[i].w;
		dfs(v,pos);
	}
}
int t[maxn*32][2],tot;
int val[maxn*32];
void insert(int x,int id)
{
	int p=0;
	for(int i=31;i>=0;i--)
	{
		int tmp=(x>>i)&1;
		if(!t[p][tmp])
			t[p][tmp]=++tot;
		p=t[p][tmp];
	}
	val[p]=id;
}
int find(int x)
{
	int p=0;
	for(int i=31;i>=0;i--)
	{
		int tmp=(x>>i)&1;
		if(t[p][tmp^1])
			p=t[p][tmp^1];
		else
			p=t[p][tmp];
	}
	return val[p];
}
void init()
{
	for(int i=0;i<=tot;i++) 
		t[i][0]=t[i][1]=0,val[i]=-1;
	memset(head,-1,sizeof(head));
	tot=0;cnt=0;
}

int main() 
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	while(~scanf("%d",&n))
	{
		init();
		for(int i=1;i<n;i++)
		{
			int x,y,w;
			scanf("%d%d%d",&x,&y,&w);
			add(x,y,w);
			add(y,x,w);
		}
		dfs(0,-1);
		int maxx=0;
		for(int i=0;i<n;i++)
		{
			int res=find(sum[i]);
			if(res!=-1)
				if(maxx<(sum[res]^sum[i]))//记得加括号,要不就有问题了。。。
					maxx=sum[res]^sum[i];
			insert(sum[i],i);
		}
		printf("%d\n",maxx);
	}
    return 0;
} 
Simulink+Simscape多体仿真:六自由度Stewart平台动力学建模全流程 本文详细介绍了使用Simulink和Simscape Multibody进行六自由度Stewart平台动力学建模的全流程,涵盖从CAD模型导入、运动学逆解计算到实时控制系统的设计。通过MATLAB/Simulink与Simscape的协同工作,实现高保真度的并联机器人仿真,适用于飞行模拟器、精密加工等高精度领域。 阅读详情

相关推荐

【HAL库-STM】智能温控按键小风扇【胎教级教学】

硬件设备:DHT11,0.96寸oled屏,二/三/四线风扇(不挑),面包板 、f10的精英板等等。当人在的风扇面前时可以自行控制风扇,不在面前时又想开风扇就让他温控自行开启,(在这里有一个想法就是加上蓝牙和wifi控制的功能能够远程遥控,这个如果做的再全一点就要自主研发是一个多功能app,这里没有做。针对这个dht11,我一开始是卡在了这个check函数里面,一直是我给完dht11低电平和高电平后,dht11不回复我低电平和高电平,这个不是我的问题,当时代码是没毛病的,这个点一直卡着我。吐血五天实现小成品

weixin_52451652的博客 1739

【POJ No. 3764】 最长xor 路径 The xor-longest Path

【POJ No. 3764】 最长xor 路径 The xor-longest Path

代码改变世界 726

一文探讨视频秒开:m3u8视频格式与视频秒开优化

秒开指的是,一秒内成功加载的播放数/播放总数。本意是想对比一下m3u8与mp4视频格式,并了解m3u8格式优缺点,以确定一个大概优化方向。但对m3u8做简单了解后,觉的m3u8可能是一个优化方向。

bjxiaxueliang的CODING小栈 2万+

POJ3764 The xor-longest Path【Trie】

The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8331 Accepted: 1733 Description In an edge-weighted tree, the xor-length of a path p is defined as the xo...

niiick 249

FPGA 学习笔记:Vivado 配置IO引脚约束

FPGA 学习笔记:Vivado 配置IO引脚约束

坚韧与专注 2万+

机器人动力学仿真软件:V-REP (CoppeliaSim)_(15).仿真项目案例分析

通过以上几个具体的仿真项目案例,我们展示了如何在V-REP (CoppeliaSim)中进行二次开发,实现复杂的机器人动力学仿真任务。这些案例涵盖了六轴机械臂的运动学仿真、移动机器人的路径规划和避障、以及无人机的飞行控制和环境感知。每个项目都通过编写Lua脚本实现了对机器人模型的控制和任务执行,并通过仿真结果分析验证了算法的有效性和系统性能。希望这些案例能够为读者在实际项目中使用V-REP (CoppeliaSim)提供有益的参考和启发。

kkchenjj的博客 1294

POJ3764(树上前缀和+Trie树)

最长异或路径 时间限制: 2000MS2000MS2000MS 空间限制: 64MB64MB64MB 题目描述 在一棵有边权的树上,一条路径ppp的异或长度定义为ppp上所有边权的异或和 xorlength(p)=⊕e∈pw(e)_{xor}length(p)=\oplus_{e \in p}^w(e)xor​length(p)=⊕e∈pw​(e) ⊕⊕⊕是异或符号。 我们认为一条路径是最长异或...

ChrysanDog的博客 465

【毕设级教程】从0到1实现基于YOLOv8的UA-DETRAC交通目标检测系统(含UI界面,助力智能交通毕设)

本项目基于YOLOv8模型和UA-DETRAC数据集开发了一个交通目标检测系统,包含数据处理、模型训练和可视化界面全流程。UA-DETRAC数据集包含多种交通场景下的车辆标注,通过格式转换适配YOLOv8训练要求。系统采用PyQt开发交互界面,支持图像检测、结果显示等功能。该项目技术路线清晰,既展现深度学习在智能交通中的应用,又提供完整的可视化展示方案,适合作为计算机视觉相关毕业设计选题。

m0_64661770的博客 149

poj 3764 最长异或路径(二进制trie树)

【问题描述】   给你一棵树,n个节点,n-1条边每条边i都有一个权值wi。定义任意两点间的权值为:这两点间的路径上的所有边的值的异或。比如a点和b点间有i,j,k三条边,那么ab两点间的权值为:wi^wj^wk。求这个最大的权值(最长异或路径)。【输入格式】   第一行为n表示节点数目(节点编号为1..n)。   接下来的n-1行,每行三个整数:u v w,表示一条树边(x,y)的权值为w(

细雨欣然 1658

在 SAP S/4HANA Cloud Public Edition 中掌控 ABAP 生命周期管理:One-Off、Multi-Off 与 Scalable Delivery 的落地方法论

本文系统梳理了SAP S/4HANA Cloud Public Edition中ABAP扩展开发的三种生命周期管理模式:One-Off适用于企业内部扩展,通过Import Collection在三系统间流转;Multi-Off面向少量客户交付,基于gCTS和Git实现不连接系统间的传输;Scalable Delivery则将扩展产品化为add-on,支持规模化分发。文章结合RAP、OData等实际开发场景,对比分析了各模式的特点与适用边界,为国内团队提供了符合Public Cloud要求的开发与交付实践建议

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1495

Python爬虫实战:股票历史数据抓取与量化回测全流程详解

我们以**东方财富网(eastmoney.com)和雪球网(xueqiu.com)**为主要目标,演示如何爬取A股历史行情。最常用的HTTP请求库,简单易用,适合静态页面数据请求。本文详细介绍了从股票历史数据抓取到简单回测的完整流程,代码示例基于最新技术,结构清晰,适合初学者和进阶者学习量化投资实战。希望对你入门Python爬虫和量化交易有所帮助!

2201_76125261的博客 1778

Poj3764---The xor-longest Path

传送门:http://poj.org/problem?id=3764 题解 注意到:对于任意一条路径的异或,表示为f(u, v) 则f(u, v) = f(1, u) ^ f(1, v) 接下来就很简单了,就是在一个数组内,找两个数异或值最大(该模型具体实现见:https://www.cnblogs.com/wangyh1008/p/9401389.html ) 代码 #include...

weixin_30618985的博客 83

小红书直播弹幕采集

本文主要介绍小红书直播间弹幕的采集,便于进行直播数据监控与直播数据进行分析。

tdl320721的博客 2540

POJ 3764 The xor-longest Path 字典树求最大异或

题意,一颗树,每个边有个值,在树上找一条简单路径,使得这条路径上的边权异或值最大 把这题模型转换一下, 对于任意一条路径的异或,表示为f(u, v) 则f(u, v) = f(1, u) ^ f(1, v) 这是显然的 其中f(1, i)是可以再O(n)内处理出来 然后就是在一个数组内,找两个数异或值最大 然后就可以用字典树来搞 每个数变成01串,  然后插入字典树,

水 5259

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ - 3764 The xor-longest Path 01字典树解决最大异或问题

原题:http://poj.org/problem?id=3764 题意:给定一棵N个节点的数,边有权值,随机选择两个点x,y,将他们路径的边上的所有边异或起来,求这样可以达到的最大值。 本来不想写这篇博客的,但是 不写似乎对不起我一个上午的自闭。 好吧先说在前面,造成这一惨烈战况的原因是,我使用了vector将边封装了起来。。 (我真是服了,内存溢出oj上显示RE,然后改了半天) ...

forOnward的博客 262

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ - 3764 The xor-longest Path(字典树性质)

题目链接:点击查看 题目大意:给出一棵树,每条边上都有一个边权,现在问能否选择两个点,使得其间路径上的异或和最大 题目分析:直接求肯定是比较复杂的,我们可以转换一下题意,因为是一棵树,所以n个点肯定互相都连通且无环,我们可以随便找一个节点当做根节点,跑一遍图的遍历,顺便记录一下根节点到每个点的路径上的异或值,我们用数组d来储存,接下来我们若想求两个点之间的路径异或,就可以直接用d[i]^d[j...

Falcon的博客 509

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ3764 The xor-longest Path (字典树) 【例题详解】

题意:   给出一棵树,求树中最长的xor路径。(n<=100000) 输入 点的数量n,之后n-1行代表x点到y点间有一条权值为z的边; 输出 最优解;   这道题与一般的最长路径不相同,因为考虑到了一个陌生的操作——异或;   异或这种东西和加减乘除还是有区别的,但是还是有一些性质让我们在计算时有据可查;以下是异或运算的性质;   1、交换律   ...

daxian3723的博客 213

【POJ 3764】The xor-longest Path

1.题目链接。题意:给一颗树,带有边权,求一下树上路径异或和最大值。 2.其实和之前BZOJ那道题有着异曲同工之妙,只需要的dfs一下,在dfs的过程中记一下当前节点到根节点的路径上的异或值,然后把这个值插到01字典树上,完事之后每次在字典树上查询最值即可,有人可能会觉得,有的点会重复计算,这样会导致出现的不是一条路径,而是两条或者多条路径交叉,其实这种情况时不存在的,因为只要一个数被计算两次,...

YG爱木木 286

POJ3764 The xor-longest Path

题意: 找出树上异或和最大的一条路径\(p\) \[ _{xor}length(p)=\oplus_{e\in_p}w(e) \] 01字典树。同样用到了简单的异或性质 \(0\oplus a = a, a\oplus a = 0\) 定义\(f(u,v)\)为\(u\)到\(v\)的路径异或和。那么\(f(u,v) = f(1,u)\oplus f(1,v)\) 所以我们可以\(d...

ACMerszl的博客 204

The xor-longest Path POJ - 3764(树上01字典树)

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§=\oplus{e \in p}w(e) ⊕ is the xor operator. We say a path the xor-longest path...

starlet_kiss的博客 373

POJ 3764 Language: The xor-longest Path (01字典树+DFS)

传送门:POJ 3764 题目大意: 在树上找一段路径(连续)使得边权相异或的结果最大。 前置技能: 用链式前向星建图。 01字典树的应用。 思路: 本题用 vector数组建图是会超时的,所以只能用链式前向星建图了。 由于是求异或的最值问题,可以考虑用 01字典树解决,又因为是在树上进行的,所以可以在 DFS遍历树的节点的同时把 当前节点到根节点相异或的结果 在01字典树中求异或的最大值并加到01字典树中去。 你可能好奇,DFS过程中并没有取消点的访问,这样为什么就能保证你所求的结果对应的路径

weixin_45767800的博客 121

POJ_3764_The xor-longest Path(01字典树)

题型:数据结构 题意:树有n个结点,每条边上有一个权值

Light_starlight 635

poj3764 The xor-longest Path(01字典树+dfs)

DescriptionIn 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.We say a path the xor-longest path if it has the largest

退役的铜牌狗 312

POJ - 3764 The xor-longest Path 01字典树求路径最大异或值

POJ - 3764 The xor-longest Path 题意: 一棵 n 个点的树,n-1 条无向带权边,求任意两点之间的所有距离异或的最大值 思路: 设d[x]为根节点到x的路径上的所有边权的异或值,显然 d[x] = d[fa[x]] xor weight(x , fa[x])。根据上式先进行一次深度优先搜索,求出所有的d[x]。设有两节点x和y,根据异或性质 a xor ...

没有梦想何以远行 362

POJ 3764 The xor-longest Path

The xor-longest Path 字典树的题目,开始看的时候毫无头绪,不知道怎么下手,看了别人的解题博客后终于明白了怎么做。这道题目出的很巧妙。之前比赛的时候遇到过一道类似的题目,不过当时我们没做出来,我们队伍还比较弱,还要奋斗啊。大致思路:由于以下式子的成立:(a^b)^(b^c) = c ,所以我们可以这样来建树,每个节点保存从根节点走到当前节点的异或值。然后我们建立一个01字典树。

BootStar 467

POJ - 3764 The xor-longest Path(树上两点路径边权异或和,01字典树)

链接:POJ - 3764 The xor-longest Path 题意: 给出一棵n(1≤n≤100000)n(1\le n\le100000)n(1≤n≤100000)个结点的树,每条边具有边权w(0≤w≤231)w(0\le w\le 2^{31})w(0≤w≤231),结点编号从000到n−1n-1n−1。要求求出 异或和最大的路径(即路径上所有边权www异或和最大),所有结点均可作为起...

Plus Ultra! 749
上一篇: HDU - 4825 - Xor Sum( 01字典树 )
下一篇: P4113 [HEOI2012]采花 ( 树状数组 + 离线 )
Cosmic_Tree
博客等级 码龄7年 134粉丝 337原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值