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了一发 最 ...
随机推荐
- tensorflow 曲线拟合
tensorflow 曲线拟合 Python代码: import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ...
- K8s爆严重安全漏洞?有何应对措施与建议
Kubernetes最近爆出严重安全漏洞,影响几乎目前所有的版本.实际影响究竟多大?老版本用户是否必须升级?以下是华为云容器服务团队对该漏洞的分析解读. Kubernetes爆出的严重安全漏洞: 攻击 ...
- PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
统计树的最小层数以及位于该层数上的叶子节点个数即可. 代码里建树我用了邻接链表的存储方式——链式前向星,不了解的可以参考,非常好用: http://www.cnblogs.com/chenxiwenr ...
- Substrings (C++ find函数应用)
Description You are given a number of case-sensitive strings of alphabetic characters, find the larg ...
- 《Linux内核分析》第三周笔记 构造一个简单的Linux系统MenuOS
构造一个简单的Linux系统MenuOS 一.linux内核源代码简介 三大法宝(存储程序计算机.函数调用堆栈.中断)和两把宝剑(中断上下文的切换:保存现场和恢复现场.进程上下文的切换) 1.在lin ...
- Opendaylight的Carbon(碳)版本安装
Opendaylight Carbon(碳)版本安装 1.更新源 sudo apt-get update sudo apt-get upgrade 2.安装JDK1.8 sudo apt-get in ...
- PAT 1048 数字加密
https://pintia.cn/problem-sets/994805260223102976/problems/994805276438282240 本题要求实现一种数字加密方法.首先固定一个加 ...
- postman 官方 test 脚本样例
Test examples 样例来源: https://learning.getpostman.com/docs/postman/scripts/test_examples/ Test scripts ...
- Helm 安装 nginx-ingress 的方法
还是没学会 今天继续研究. Using Helm NGINX Ingress controller can be installed via Helm using the chart stable/n ...
- javascript 设置input 输入框里面的内容
比如百度首页的输入框 id为kw 用javascript:document.getElementById('kw').value="杀手 博客园";用jQuery:$(" ...