bzoj千题计划194:bzoj2115: [Wc2011] Xor
http://www.lydsy.com/JudgeOnline/problem.php?id=2115
边和点可以重复经过,那最后的路径一定是从1到n的一条路径加上许多环
dfs出任意一条路径的异或和、路径上所有环的异或和,加入线性基即可
#include<cstdio>
#include<iostream> using namespace std; #define N 50001
#define M 100001 typedef long long LL; int n; int tot,front[N],to[M<<],nxt[M<<];
LL val[M<<]; bool vis[N]; int cnt;
LL dis[N];
LL a[M<<]; LL b[]; template<typename T>
void read(T &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v,LL w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=w;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; val[tot]=w;
} void dfs(int x,int y)
{
vis[x]=true;
for(int i=front[x];i;i=nxt[i])
if(to[i]!=y)
{
if(!vis[to[i]]) dis[to[i]]=dis[x]^val[i],dfs(to[i],x);
else a[++cnt]=dis[to[i]]^dis[x]^val[i];
}
} void solve()
{
for(int i=;i<=cnt;++i)
for(int j=;j>=;--j)
if(a[i]>>j&)
{
if(!b[j])
{
b[j]=a[i];
break;
}
a[i]^=b[j];
}
LL ans=dis[n];
for(int i=;i>=;--i)
if((ans^b[i])>ans) ans^=b[i];
cout<<ans;
} int main()
{
int m;
read(n); read(m);
int u,v;
LL w;
while(m--)
{
read(u); read(v); read(w);
add(u,v,w);
}
dfs(,);
solve();
return ;
}
2115: [Wc2011] Xor
Time Limit: 10 Sec Memory Limit: 259 MB
Submit: 4064 Solved: 1691
[Submit][Status][Discuss]
Description

Input
第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目。 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边。 图中可能有重边或自环。
Output
仅包含一个整数,表示最大的XOR和(十进制结果),注意输出后加换行回车。
Sample Input
1 2 2
1 3 2
2 4 1
2 5 1
4 5 3
5 3 4
4 3 2
Sample Output
HINT

bzoj千题计划194:bzoj2115: [Wc2011] Xor的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划191:bzoj2337: [HNOI2011]XOR和路径
http://www.lydsy.com/JudgeOnline/problem.php?id=2337 概率不能异或 但根据期望的线性,可以计算出每一位为1的概率,再累积他们的期望 枚举每一位i,现 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
随机推荐
- wkhtmltopdf 参数介绍
wkhtmltopdf [OPTIONS]... <input file> [More input files] <output file> 常规选项 --allow &l ...
- C#集合与泛型集合
看到这个标题,大家应该就知道有泛型集合,就有非泛型集合 既然都是集合,咱们今儿就简单的来对比讲解下 需要记住的不算太多,理解记忆.理解记忆 2017-11-0411:39:09 C# 泛型集合之非泛型 ...
- jumpserver部署
1.部署环境.安装依赖包 # yum install git python-pip mysql-devel gcc automake autoconf python-devel vim sshpass ...
- 利用BFS实现最短路
首先,我们要知道BFS的思想,BFS全称是Breadth-First-Search. 二叉树的BFS:通过BFS访问,它们的访问顺序是它们到根节点距离从小到大的排序. 图的BFS:同样的,离起点越近, ...
- 微软职位内部推荐-Sr. SE - Office incubation
微软近期Open的职位: Senior Software Engineer-Office Incubation Office China team is looking for experienced ...
- 微软职位内部推荐-Senior BSP Engineer
微软近期Open的职位: The position of Sr. BSP engineer requires experience and good knowledge in mobile hardw ...
- LeetCode 633. 平方数之和
题目: 给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2 ...
- 软工结对项目之词频统计update
队友 胡展瑞 031602215 作业页面 GitHub 具体分工 111500206 赵畅:负责WordCount的升级,添加新的命令行参数支持(自定义输入输出文件,权重词频统计,词组统计等所有新功 ...
- ubuntu 12.04下 eclipse的安装
1首先下载有关的JDK sudo apt-get install openjdk-7-jre 由于是源内的东西,所以只许执行上面这一步,就自动帮你下载 安装 以及配置,无需繁琐的操作. 这里ubunt ...
- BZOJ2431 HAOI2009逆序对数列(动态规划)
对于排列计数问题一般把数按一个特定的顺序加入排列.这个题做法比较显然,考虑将数从小到大加入排列即可. #include<iostream> #include<cstdio> # ...