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

题解:

卡点:

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. [优化]Steamroller-freecodecamp算法题目

    晚上在medium看到一篇关于找工作的文章,里面提到一个面试题目--flattening an array(扁平化数组).这我好像在哪看过!应该是freecodecamp里的算法某一题.翻了下博客记录 ...

  2. STL 之 set的应用

    关于set Set是STL中的一个容器,特点是其中包含的元素值是唯一的,set根据其底层实现机制分为hash存储和红黑树存储两种方式,这两种结构最本质的区别就是有序和无序,红黑树的存储是有序的而has ...

  3. django+xadmin在线教育平台(八)

    4-5 user modesl.py设计 循环引用: 设计app时每个app都有model   mark 如图:我们在user中定义usercourse记录用户学习的课程.会有两个外键:user和co ...

  4. 超简单开发自己的php框架一点都不难

    (转)https://blog.csdn.net/qq_33862644/article/details/79344331 写框架的极简思路: 接收,打印参数想怎么弄.如 获取配置文件的方法,根据传过 ...

  5. ubuntu安装tomcat7

    1. 下载apache-tomcat-7.0.64.tar.gz 进入tomcat官网:http://tomcat.apache.org/download-70.cgi下载相应的压缩包: 2. 上传安 ...

  6. Python 编码格式的使用

    编码史 ASCII > Unicode > UTF-8 Unicode支持多语言,UTF-8自动转换长短细节节省空间 在计算机内存中,统一使用Unicode编码,当需要保存到硬盘或者需要传 ...

  7. 硬盘安装Windows Server 2008(解决系统盘符变成D盘)

    硬盘安装Windows 2008系统方法 操作系统最好用的无疑是server 2003,但是现在Server 2003支持的软件越来越少,很多是故意不支持Server 2003了, 像php5.5以上 ...

  8. 区间DP入门题目合集

      区间DP主要思想是先在小区间取得最优解,然后小区间合并时更新大区间的最优解.       基本代码: //mst(dp,0) 初始化DP数组 ;i<=n;i++) { dp[i][i]=初始 ...

  9. [BSGS]大步小步算法

    问题 BSGS被用于求解离散对数,即同余方程: \[ A^x\equiv B\pmod{P} \] 求\(x\)的最小非负整数解. 保证\(A\perp P\)(互质). 分析 首先,我们根据费马小定 ...

  10. 多个".h"文件中声明及定义 全局变量和函数

    一.".h"文件必须以如下格式书写 例:文件<CZ_efg_hi.h"> ------------文件内容----------- #ifndef CZ_Efg ...