BZOJ2115 [Wc2011] Xor 【线性基】
2115: [Wc2011] Xor
Time Limit: 10 Sec Memory Limit: 259 MB
Submit: 3915 Solved: 1633
[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

弄了那么久还是讲不清楚线性基是什么
大概就是在异或时去除掉一些重复的元素,使得剩下的元素异或不出0且值域覆盖原来的异或值域?
学完回来补坑
除此之外,就是找到1到N的一条路径,对于路径上所有的环记录下来进行一次高斯消元,贪心异或即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = head[u]; k != -1; k = edge[k].next)
using namespace std;
const int maxn = 50005,maxm = 200005,INF = 1000000000;
inline LL RD(){
LL out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 1) + (out << 3) + c - '0'; c = getchar();}
return out * flag;
}
LL N,M,d[maxn],V[maxm],A[65],cir = 0,tot = 0,bin[65];
bool vis[maxn];
int head[maxn],nedge = 0;
struct EDGE{LL to,w,next;}edge[maxm];
inline void build(int u,int v,LL w){
edge[nedge] = (EDGE){v,w,head[u]}; head[u] = nedge++;
edge[nedge] = (EDGE){u,w,head[v]}; head[v] = nedge++;
}
void dfs(int u){
vis[u] = true; int to;
Redge(u) if (!vis[to = edge[k].to]){
d[to] = d[u] ^ edge[k].w;
dfs(to);
}else V[++cir] = d[to] ^ d[u] ^ edge[k].w;
}
void gaosi(){
for (LL j = bin[60]; j; j >>= 1){
int i = tot + 1;
while (i <= cir && !(V[i] & j)) i++;
if (i == cir + 1) continue;
swap(V[++tot],V[i]);
for (int k = 1; k <= cir; k++)
if (k != tot && (V[k] & j))
V[k] ^= V[tot];
}
}
int main(){
bin[0] = 1;REP(i,60) bin[i] = bin[i - 1] << 1;
memset(head,-1,sizeof(head));
N = RD(); M = RD(); LL a,b,w;
while (M--){
a = RD(); b = RD(); w = RD();
build(a,b,w);
}
dfs(1); gaosi();
LL ans = d[N];
for (int i = 1; i <= cir; i++)
ans = max(ans,ans ^ V[i]);
cout<<ans<<endl;
return 0;
}
BZOJ2115 [Wc2011] Xor 【线性基】的更多相关文章
- BZOJ2115:[WC2011] Xor(线性基)
Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...
- 【BZOJ-2115】Xor 线性基 + DFS
2115: [Wc2011] Xor Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2142 Solved: 893[Submit][Status] ...
- BZOJ.2115.[WC2011]Xor(线性基)
题目链接 \(Description\) 给定一张无向带边权图(存在自环和重边).求一条1->n的路径,使得路径经过边的权值的Xor和最大.可重复经过点/边,且边权和计算多次. \(Soluti ...
- BZOJ 2115 [Wc2011] Xor ——线性基
[题目分析] 显然,一个路径走过两边是不需要计算的,所以我么找到一条1-n的路径,然后向该异或值不断异或简单环即可. 但是找出所有简单环是相当复杂的,我们只需要dfs一遍,找出所有的环路即可,因为所有 ...
- BZOJ 2115: [Wc2011] Xor 线性基 dfs
https://www.lydsy.com/JudgeOnline/problem.php?id=2115 每一条从1到n的道路都可以表示为一条从1到n的道路异或若干个环的异或值. 那么把全部的环丢到 ...
- bzoj2115 [Wc2011] Xor——高斯消元 & 异或线性基
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2115 异或两次同一段路径的权值,就相当于没有走这段路径: 由此可以得到启发,对于不同的走法, ...
- bzoj千题计划194:bzoj2115: [Wc2011] Xor
http://www.lydsy.com/JudgeOnline/problem.php?id=2115 边和点可以重复经过,那最后的路径一定是从1到n的一条路径加上许多环 dfs出任意一条路径的异或 ...
- Xor && 线性基练习
#include <cstdio> #include <cstring> ; ; int cnt,Ans,b,x,n; inline int Max(int x,int y) ...
- BZOJ2115 [Wc2011] Xor
Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...
随机推荐
- 简易的vuex用法
vuex是vue中用于管理全局状态的一个组件,用于不同组件之间的通信,下面将介绍它的简单用法 首先安装vue与vuex npm install vue npm install vuex --save ...
- jquery之prop与attr区别。
一切看下面代码示例<!DOCTYPE html> <html> <head> <title>全选和反选</title> <script ...
- js获取播放器播放时间和停止播放
html代码 <video id="myVideo" class="video-active" width="100%" height ...
- Hadoop(25)-高可用集群配置,HDFS-HA和YARN-HA
一. HA概述 1. 所谓HA(High Available),即高可用(7*24小时不中断服务). 2. 实现高可用最关键的策略是消除单点故障.HA严格来说应该分成各个组件的HA机制:HDFS的HA ...
- ionic 做移动应用怎么样?
看了很多网上的赞美性介绍后,我们选用了这个做开发,目前碰到的坑有: android, list界面上下滑动会lag ios下,当键盘弹出时,你可以选择整个页面scroll,也可以选择不scroll,但 ...
- liunx下搭建python开发环境
=============================================================================注意: 在linux下安装新的版本的pytho ...
- Java学习笔记十:Java的数组以及操作数组
Java的数组以及操作数组 一:什么是数组: 数组可以理解为是一个巨大的“盒子”,里面可以按顺序存放多个类型相同的数据,比如可以定义 int 型的数组 scores 存储 4 名学生的成绩 数组中的元 ...
- DLX算法一览
目录: 1 X思想的了解. 链表的递归与回溯. 具体操作. 优化. 一些应用与应用中的再次优化(例题). 练手题 X思想的了解. 首先了解DLX是什么? DLX是一种多元未饱和型指令集结构,DLX 代 ...
- 基于jQuery的2048小游戏设计(网页版)
上周模仿一个2048小游戏,总结一下自己在编写代码的时候遇到的一些坑. 游戏规则:省略,我想大部分人都玩过,不写了 源码地址:https://github.com/xinhua6/2048game.g ...
- Ubuntu14.04安装opencv2.4.13
本文参考相关链接:http://blog.csdn.net/honyniu/article/details/46390097 系 统:Ubuntu 14.04 x64 opencv版本:2.4.1 ...