[CF845G]Shortest Path Problem?
题目大意:同这道题,只是把最大值变成了最小值
题解:略
卡点:无
C++ Code:
#include <cstdio>
#define maxn 100010
#define maxm 100010
int head[maxn], cnt;
struct Edge {
int to, nxt;
long long w;
} e[maxm << 1];
void addE(int a, int b, long long c) {
e[++cnt] = (Edge) {b, head[a], c}; head[a] = cnt;
} long long p[64];
inline void add(long long x) {
for (int i = 62; ~i; i--) if (x & 1ll << i) {
if (p[i]) x ^= p[i];
else {p[i] = x; break;}
}
}
inline long long ask(long long x) {
long long ans = x;
for (int i = 62; ~i; i--) if (ans > (ans ^ p[i])) ans = ans ^ p[i];
return ans;
} long long d[maxn];
bool vis[maxn];
void dfs(int rt, long long now) {
d[rt] = now;
vis[rt] = true;
for (int i = head[rt]; i; i = e[i].nxt) {
int v = e[i].to;
if (!vis[v]) dfs(v, d[rt] ^ e[i].w);
else add(d[rt] ^ d[v] ^ e[i].w);
}
}
int n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
long long c;
scanf("%d%d%lld", &a, &b, &c);
addE(a, b, c);
addE(b, a, c);
}
dfs(1, 0);
printf("%lld\n", ask(d[n]));
return 0;
}
[CF845G]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 ...
- 线性基【CF845G】Shortest Path Problem?
Description 给定一张 \(n\) 个点 \(m\) 条边的无向图,一开始你在点 \(1\),且价值为 \(0\) 每次你可以选择一个相邻的点,然后走过去,并将价值异或上该边权 如果在点 \ ...
- 【CF edu 27 G. Shortest Path Problem?】
time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...
- Codeforces 845G Shortest Path Problem?
http://codeforces.com/problemset/problem/845/G 从顶点1dfs全图,遇到环则增加一种备选方案,环上的环不需要走到前一个环上作为条件,因为走完第二个环可以从 ...
- 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 ...
- Why longest path problem doesn't have optimal substructure?
We all know that the shortest path problem has optimal substructure. The reasoning is like below: Su ...
- hdu-----(2807)The Shortest Path(矩阵+Floyd)
The Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- GCD中的线程死锁问题
GCD 确实好用 ,很强大,相比NSOpretion 无法提供 取消任务的功能. 如此强大的工具用不好可能会出现线程死锁. 如下代码: - (void)viewDidLoad { [super vie ...
- ES6的数组方法之Array.from
首先说说什么是数组:数组在类型划分上归为Object,属于比较特殊的对象,数组的索引值类似于对象的key值. 数组的几个注意点: 1.数组的长度是可读属性,不可更改,数组的长度根据索引最大值. 2.数 ...
- CBCGPImage的GetSize的问题及解决方法
BCGControlBar Pro for MFC 25.10是目前(2018-07-16)网上能够找到的最新能够使用的版本,我配合Visual Studio 2010使用.在单文档MFC程序的视图中 ...
- html之table&select不为人知的操作
table标签和其它标签不一样,他有属性和方法! table属性: rows 可以得到table的row集合 cells 得到table所有单元格 table方法: insertR ...
- Laravel系列之CMS系统学习 — 角色、权限配置【1】
一.后台Admin模块 后台管理是有管理员的,甚至超级管理员,所以在设计数据表的时候,就会有2个方案,一个方案是共用users数据表,添加is_admin,is_superAdmin字段来进行验证,或 ...
- html5中的progress兼容ie,制作进度条样式
html5新增的progress标签用处很大,它可以制作进度条,不用像以前那样用css来制作进度条! 一.progress使用方法 progress标签很好使用,他有两个属性,value和max,va ...
- Python学习第一弹
开发语言: 高级:Python.java.PHP C# GO ruby C++ ——>字节码 低级:C.汇编 ...
- Fruits【水果】
Fruits Many of us love July because it's the month when nature's berries and stone fruits are in abu ...
- VUE前端无法启动
cd 到client中,使用npm run dev ,一直卡着也不报错,启动不了项目 可以直接使用 ,需要进入root目录进行 cnpm install npm -g
- IIS发布错误记录
1.HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. 详细错误信息模块 IIS Web Core 通知 BeginRequ ...