题目大意:这道题,只是把最大值变成了最小值

题解:

卡点:

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?的更多相关文章

  1. 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 ...

  2. 干货 | 列生成VRPTW子问题ESPPRC( Elementary shortest path problem with resource constraints)介绍附C++代码

    00 前言 各位小伙伴大家好,相信大家已经看过前面column generation求解vehicle routing problems的过程详解.该问题中,子问题主要是找到一条reduced cos ...

  3. 线性基【CF845G】Shortest Path Problem?

    Description 给定一张 \(n\) 个点 \(m\) 条边的无向图,一开始你在点 \(1\),且价值为 \(0\) 每次你可以选择一个相邻的点,然后走过去,并将价值异或上该边权 如果在点 \ ...

  4. 【CF edu 27 G. Shortest Path Problem?】

    time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...

  5. Codeforces 845G Shortest Path Problem?

    http://codeforces.com/problemset/problem/845/G 从顶点1dfs全图,遇到环则增加一种备选方案,环上的环不需要走到前一个环上作为条件,因为走完第二个环可以从 ...

  6. AT [ABC177F] I hate Shortest Path Problem

    因为每行只有一个区域不能往下走,因此我们可以来分析一下从起点到整个矩形每个位置的最短路.可以发现每一行的最短路只与上一行的最短路有关,假设我们知道上一行的最短路,上一行不能往下走的区间在 \([L, ...

  7. 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 ...

  8. 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 ...

  9. hdu-----(2807)The Shortest Path(矩阵+Floyd)

    The Shortest Path Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

随机推荐

  1. react中实现原生enter/回车事件及antdesign组件实现方式

    先直接上核心代码: this.goToHomePage换成自己逻辑 自己写的时候直接把this.goToHmoPage()换成自己的逻辑就行了,还有注意一点的是: 需要传个空函数,不然会报错 在com ...

  2. OA上传和编辑数据

    1.VO:value object值对象.通常用于业务层之间的数据传递,和PO一样也是仅仅包含数据而已.但应是抽象出的业务对象,可以和表对应,也可以不,这根据业务的需要. 2. String[]类型打 ...

  3. jquery 配合 ajax 完成 在线编辑 你值得拥有

    思路分析: 将 table中的表格 改变成为 input表格框获得值 ajax配合修改 删除 <?php use yii\helpers\Url; $web = Url::base(); ?&g ...

  4. 适配IE8+等浏览器的适配播放插件

    function myBrowser(){ var userAgent = navigator.userAgent; //ȡ���������userAgent�ַ� var isOpera = us ...

  5. MySQL CONCAT()与GROUP_CONCAT()的使用

      1 . MySQL CONCAT(str1,str2, ...)  --返回连接的字符串 mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQ ...

  6. html_parser.py

    coding=UTF-8 # HTML解释器 import re from bs4 import BeautifulSoup class htmlParser(): def parse(self, u ...

  7. ZOJ 3329 Problem Set (期望dp)

    One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...

  8. 《Cracking the Coding Interview》——第11章:排序和搜索——题目6

    2014-03-21 21:50 题目:给定一个MxN的二位数组,如果每一行每一列都是升序排列(不代表全展开成一个一维数组仍是升序排列的).请设计一个算法在其中查找元素. 解法:对于这么一个数组,有两 ...

  9. 《Cracking the Coding Interview》——第1章:数组和字符串——题目5

    2014-03-18 01:40 题目:对字符串进行类似游程编码的压缩,如果压缩完了长度更长,则返回不压缩的结果.比如:aabcccccaaa->a2b1c5a3,abc->abc. 解法 ...

  10. Bit与Byte的区别

    在工作中遇到一些概念模糊的地方, 需要记住了bit意为“位”或“比特”,是计算机运算的基础: byte意为“字节”,是计算机文件大小的基本计算单位: 说到usb2.0标准接口传输速率.许多人都将“48 ...