Codeforces 845G Shortest Path Problem?
http://codeforces.com/problemset/problem/845/G
#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
vector<int> v;
struct EDGE{
int to,next,len;
EDGE(){
}
EDGE(int a,int b,int c){
to = a,next = b,len = c;
}
}e[maxn<<];
int vis[maxn],st,ed,cnt,head[maxn],val[maxn],len;
void add(int u,int v,int len){
e[++cnt] = EDGE(v,head[u],len);
head[u] = cnt;
}
void add(int x){
for(int i = ;i<(int)v.size();i++){
x = min(x,x^v[i]);
}
if(x) v.push_back(x);
}
void dfs(int x,int now){
vis[x] = ;
for(int i = head[x];i;i = e[i].next){
int to = e[i].to;
if(vis[to]) add(val[to]^now^e[i].len);
else{
val[to] = now^e[i].len;
dfs(to,val[to]);
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i = ;i<m;i++){
scanf("%d%d%d",&st,&ed,&len);
add(st,ed,len);
add(ed,st,len);
}
dfs(,);
for(int i = ;(int)i<v.size();i++){
val[n] = min(val[n],val[n]^v[i]);
}
return *printf("%d",val[n]);
}
8/28更新
https://csacademy.com/contest/archive/task/xor_cycle
一道类似的题,同样是找出所有环,最后组合出最大结果输出即可
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int n,m;
vector<pair<int,long long> > node[];
int vis[],a,b;
long long val[];
long long _len;
vector<long long> base;
void add(long long x){
for(int i = ;i<base.size();i++){
x = min(x,x^base[i]);
}
if(x) base.push_back(x);
}
void dfs(int x,int fa){
for(int i = ;i<node[x].size();i++){
int to = node[x][i].first;
long long len = node[x][i].second;
if(to == fa) continue;
if(!vis[to]){
vis[to] = ;
val[to] = val[x]^len;
dfs(to,x);
}
else{
add(val[to]^len^val[x]);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
cin>>n>>m;
for(int i = ;i<m;i++){
cin>>a>>b>>_len;
node[a].push_back(make_pair(b,(long long)_len));
node[b].push_back(make_pair(a,(long long)_len));
}
dfs(,-);
long long ans = ;
for(int i = ;i<base.size();i++){
ans = max(ans,ans^base[i]);
}
cout<<ans<<endl;
return ;
}
Codeforces 845G Shortest Path Problem?的更多相关文章
- Codefroces Educational Round 27 845G Shortest Path Problem?
Shortest Path Problem? You are given an undirected graph with weighted edges. The length of some pat ...
- 干货 | 列生成VRPTW子问题ESPPRC( Elementary shortest path problem with resource constraints)介绍附C++代码
00 前言 各位小伙伴大家好,相信大家已经看过前面column generation求解vehicle routing problems的过程详解.该问题中,子问题主要是找到一条reduced cos ...
- Codeforces 938G Shortest Path Queries [分治,线性基,并查集]
洛谷 Codeforces 分治的题目,或者说分治的思想,是非常灵活多变的. 所以对我这种智商低的选手特别不友好 脑子不好使怎么办?多做题吧-- 前置知识 线性基是你必须会的,不然这题不可做. 推荐再 ...
- 【CF edu 27 G. Shortest Path Problem?】
time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...
- node搜索codeforces 3A - Shortest path of the king
发一下牢骚和主题无关: 搜索,最短路都可以 每日一道理 人生是洁白的画纸,我们每个人就是手握各色笔的画师:人生也是一条看不到尽头的长路,我们每个人则是人生道路的远足者:人生还像是一块神奇的土地 ...
- 线性基【CF845G】Shortest Path Problem?
Description 给定一张 \(n\) 个点 \(m\) 条边的无向图,一开始你在点 \(1\),且价值为 \(0\) 每次你可以选择一个相邻的点,然后走过去,并将价值异或上该边权 如果在点 \ ...
- [CF845G]Shortest Path Problem?
题目大意:同这道题,只是把最大值变成了最小值 题解:略 卡点:无 C++ Code: #include <cstdio> #define maxn 100010 #define maxm ...
- AT [ABC177F] I hate Shortest Path Problem
因为每行只有一个区域不能往下走,因此我们可以来分析一下从起点到整个矩形每个位置的最短路.可以发现每一行的最短路只与上一行的最短路有关,假设我们知道上一行的最短路,上一行不能往下走的区间在 \([L, ...
- Solve Longest Path Problem in linear time
We know that the longest path problem for general case belongs to the NP-hard category, so there is ...
随机推荐
- phpcms后台添加会员报v9_sso_member表缺失
坑货..表前缀设置 两个地方都有 一个是默认的caches/configs/目录 还有个是phpsso_server/caches/configs/ 如果改了表前缀 这两个地方的database都要改 ...
- Ubuntu 16.04 RabbitMq 安装与运行
前言目前公司用阿里云 + redis 的方式实现的消息队列.了解了目前几种主流的消息组件(主要包括rabbitmq.kafka.)的优缺点后,这里为了深入学习rabbitmq,我在自己的腾讯云服务器上 ...
- elasticsearch查询操作
#查看节点信息 curl -X GET http://localhost:9200/_nodes #打开文件数信息 curl -X GET http://localhost:9200/_nodes/s ...
- 虚拟机中CentOS 7 x64图形化界面的安装
VMware的初始设置如下: 图1 待虚拟机读取完iso,出现此界面 图2 我们主要是安装图形化界面的系统,所以在软件选择栏下如图选择: 图3 设置root密码,创建用户,等候安装完成: 图4 安装完 ...
- Linux 系统信息查询大全
Linux常用系统命令 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /etc/redhat-release ...
- Linux 如何找到100M以上的大文件
find / -type f -size +100000k |xargs ls -lh|awk '{print $9 ":" $5}'
- mybatis+mysql insert添加数据后返回数据主键id
1.根据useGeneratedKeys获取返回值,部分数据库不支持 修改mybatis xml <insert id="insertUser" useGeneratedKe ...
- jquery 实时监听输入框值变化的完美方案
只需要同时绑定 oninput 和 onpropertychange 两个事件,但是这并不完美 $('.input-form :input').bind('input propertychange', ...
- 注意了,Mybatis中条件判断时遇到的坑
1.mapper中比较字符串时需要注意的问题如下: mybatis 映射文件中,if标签判断字符串相等,两种方式:因为mybatis映射文件,是使用的ognl表达式,所以在判断字符串isComplet ...
- 补码一位乘法 Booth算法 Java简易实现
本文链接:https://www.cnblogs.com/xiaohu12138/p/11955619.html. 转载,请说明出处. 本程序为简易实现补码一位乘法,若代码中存在错误,可指出,本人会不 ...