【BZOJ】【P1954】【Pku3764 The xor-longest Path】【题解】【Trie】
来源:互联网 发布:高仿京东商城app源码 编辑:程序博客网 时间:2024/06/05 16:35
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1954
水题……3min写完1A……
Code:
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;struct edge{int u,v,w;};vector<edge>G[maxn];int n,m,a[maxn];void dfs(int u,int fa){for(int i=0;i<G[u].size();i++){edge e=G[u][i];if(e.v==fa)continue;a[e.v]=a[u]^e.w;dfs(e.v,u);}}int ch[maxn<<4][2],tot;short val[maxn<<4];void insert(int x){int bit[32];for(int i=0;i<32;i++)bit[i]=x>>i&1;int u=0;for(int i=31;i>=0;i--){if(!ch[u][bit[i]])ch[u][bit[i]]=++tot;u=ch[u][bit[i]];}val[u]=1;}int Qmax(int x){int bit[32];for(int i=0;i<32;i++)bit[i]=x>>i&1;int u=0,ans=0;for(int i=31;i>=0;i--){if(ch[u][!bit[i]]){ans|=(!bit[i])<<i;u=ch[u][!bit[i]];}else{ans|=bit[i]<<i;u=ch[u][bit[i]];}}return ans;}int main(){scanf("%d",&n);for(int i=1;i<n;i++){int u,v,w;scanf("%d%d%d",&u,&v,&w);G[u].push_back((edge){u,v,w});G[v].push_back((edge){v,u,w});}dfs(1,1);int ans=0;for(int i=1;i<=n;i++)insert(a[i]);for(int i=1;i<=n;i++)ans=max(ans,a[i]^Qmax(a[i]));cout<<ans<<endl;return 0;}
0 0
- 【BZOJ】【P1954】【Pku3764 The xor-longest Path】【题解】【Trie】
- BZOJ P1954: Pku3764 The xor-longest Path
- 【BZOJ 1954】Pku3764 The xor-longest Path trie+贪心
- [BZOJ1954]Pku3764 The xor-longest Path
- BZOJ1954 Pku3764 The xor-longest Path
- bzoj1954: Pku3764 The xor-longest Path
- 1954: Pku3764 The xor-longest Path 0-1字典树
- 【bzoj1954】【The xor-longest Path】【trie树】
- trie-bzoj1954-poj3764-The xor-longest Path
- POJ 3764 The xor-longest Path Trie
- POJ 3764[The xor-longest Path]题解
- Poj 3764 The xor-longest Path(Trie树+xor+贪心)
- poj - 3764 - The xor-longest Path(Trie)
- 【POJ3764】The xor-longest Path Trie树+异或性质
- POJ 3764 The xor-longest Path trie树+贪心
- POJ 3764 The xor-longest Path (Trie树 + dfs)
- poj 3764 The xor-longest Path (Trie树)
- POJ 3764 The xor-longest Path Trie树/字典树
- Linux c 开发 - libevent
- listView/GridView getChild获取不到的解决方法
- android listview addheadview
- 数据库索引的作用和优点缺点
- EM算法与混合高斯模型
- 【BZOJ】【P1954】【Pku3764 The xor-longest Path】【题解】【Trie】
- UVa #140 Bandwidth (例题7-6)
- 关于Ext.onReady的调用方法
- 通过Volley实现ListView加载大量图片(Demo是2000张)
- 快速排序
- C++实现高精度乘法
- UNIX环境高级编程-第0章- 关于apue.h和源码编译问题
- 八卦一下
- C#实现“生产者消费者”问题