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 ...
随机推荐
- eclipse、MyEclipse 修改字符集和JDK
eclipse 中UTF-8设置 1.windows->Preferences 打开"首选项"对话框: 2.然后,general->Workspace,右 侧Tex ...
- ORA-03114: not connected to ORACLE
PlSql Developer出现这个问题的时候,只要重新连接一些数据库就行了!
- C#程序 界面显示运行信息
1.使用RichTextBox,难免要在多线程调用,所以需要委托. Color定义此条信息用什么颜色显示.可以不同的颜色显示不同的信息. private void ShowMsg(Color colo ...
- 从字节跳动离职后,拿到探探、趣头条、爱奇艺、小红书、15家公司的 offer【转】
前言 博主目前从事Android开发3年,前两年一直在抖音工作.我这篇文章并不是简单的描述一些面试中的题,或者总结一些Android的知识,而是想记录我整个的想法和准备的过程,以及一些心得体会,让大家 ...
- python logging模块【转载】
转自:https://www.cnblogs.com/dahu-daqing/p/7040764.html 参考:老顽童log模块,讲的很细致,基本上拿到手就可以直接用了,很赞 1 logging模块 ...
- ffmpeg学习笔记-音频播放
前文讲到音频解码,将音频解码,并且输入到PCM文件,这里将音频通过AudioTrack直接输出 音频播放说明 在Android中自带的MediaPlayer也可以对音频播放,但其支持格式太少 使用ff ...
- 最新 58集团java校招面经 (含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.58集团等10家互联网公司的校招Offer,因为某些自身原因最终选择了58集团.6.7月主要是做系统复习.项目复盘.Leet ...
- php遇到Allowed memory size of 134217728 bytes exhausted问题解决方法
终端报出了Allowed memory size of 134217728 bytes exhausted错误,而且重启电脑再次执行仍然是一样.上网查了查,是因为php默认内存限制是128M,所以需要 ...
- Linux中tftp安装及使用笔记
tftp命令用在本机和tftp服务器之间使用TFTP协议传输文件. TFTP是用来下载远程文件的最简单网络协议,它其于UDP协议而实现. linux服务器端tftp-server的配置 1.安装tft ...
- 关于Android的资源id
1 @+id/xx 这个表示向资源文件中添加一个新的id. @+id是在R文件中生成int xxx=value. 有两种情况 ①R文件中不存在xxx变量,则生成int xxx=value即为控件新建一 ...