Run For Beer CF575G
Run for beer
CF 575G
如果直接bfs分层贪心可以做,但是很毒瘤,具体可以参考Gavinzheng的提交
考虑魔改dijkstra
首先,每次拿权值最小的来松弛肯定没有问题,只是怎么表示路径长度
由于边权很小,我们只需要拿 排名 * 10 + w 当权值就可以了。
这里的“权值”是相对的权值,具体可以看代码。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
//#define int long long
#define MAXN 100016
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define inf 0x3f3f3f3f
#define cmx( a , b ) a = max( a , b )
#define cmn( a , b ) a = min( a , b )
int n , m;
int head[MAXN] , to[MAXN << 1] , wto[MAXN << 1] , nex[MAXN << 1] , ecn;
void ade( int u , int v , int w ) {
to[++ecn] = v , nex[ecn] = head[u] , wto[ecn] = w , head[u] = ecn;
}
int dis[MAXN] , len[MAXN] , pre[MAXN] , done[MAXN];
priority_queue<pii , vector<pii> , greater<pii> > Q;
queue<int> q;
void dijk( int s ) {
memset( dis , 0x3f , sizeof dis );
memset( len , 0x3f , sizeof len );
memset( pre , -1 , sizeof pre );
dis[s] = 0 , len[s] = 1;
q.push( s );
while( !q.empty() ) {
int u = q.front(); q.pop( );
for( int i = head[u] ; ~i ; i = nex[i] ) {
int v = to[i];
Q.push( mp( 0 , u ) );
if( dis[v] && ! wto[i] )
q.push( v ) , dis[v] = 0 , pre[v] = ( i ^ 1 ) , len[v] = len[u] + 1;
}
}
int rnk = 0 , last = -1;
while( !Q.empty() ) {
pii too = Q.top( ); Q.pop( );
int u = too.se;
if( done[u] ) continue;
done[u] = true;
if( last != dis[u] ) last = dis[u] , ++ rnk;
for( int i = head[u] ; ~i ; i = nex[i] ) {
int v = to[i];
if( dis[v] > rnk * 10 + wto[i] ) {
dis[v] = rnk * 10 + wto[i];
pre[v] = ( i ^ 1 );
len[v] = len[u] + 1;
Q.push( mp( dis[v] , v ) );
} else if( dis[v] == rnk * 10 + wto[i] && len[v] > len[u] + 1 ) {
pre[v] = ( i ^ 1 );
len[v] = len[u] + 1;
Q.push( mp( dis[v] , v ) );
}
}
}
}
int main() {
memset( head , -1 , sizeof head ) , ecn = -1;
cin >> n >> m;
for( int i = 1 , u , v , w ; i <= m ; ++ i ) {
scanf("%d%d%d",&u,&v,&w);
++ u , ++ v;
ade( u , v , w ) , ade( v , u , w );
}
dijk( n );
int c = 1;
stack<int> sss;
while( c != n )
sss.push( wto[pre[c]] ) , c = to[pre[c]];
while( !sss.empty() && sss.top() == 0 ) sss.pop();
if( sss.empty() ) printf("0");
else while( !sss.empty() ) printf("%d",sss.top()) , sss.pop();
puts("");
printf("%d\n" , len[1]);
c = 1;
printf("%d ",0);
while( c != n )
c = to[pre[c]] , printf("%d ",c - 1);
}
Run For Beer CF575G的更多相关文章
- Bubble Cup 8 finals G. Run for beer (575G)
题意: 给定一个带权无向图,每条边的代价为边权/当前速度,每次到达一个新节点,速度都会除以10. 求0号点到n-1号点的最小代价,如果多解输出点数最少的解,输出代价.路径点数.路径经过的点. 1< ...
- Solution -「CF 575G」Run for beer
\(\mathcal{Description}\) Link. 给定 \(n\) 个点 \(m\) 条边的无向图,边有边权,一个人初始速度为 \(1\),每走一条边速度 \(\div10\), ...
- can't run roscore 并且 sudo 指令返回 unable to resolve host
I'm using ubuntu14 LTS. Problems: 1. When run roscore, got a mistake and an advice to ping the local ...
- DotNet Run 命令介绍
前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...
- 布里斯班Twilight Bay Run半程马拉松
自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...
- SVN:Previous operation has not finished; run 'cleanup' if it was interrupted
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...
- linux 环境下运行STS时 出现must be available in order to run STS
linux 环境下运行ECLIPSE时 出现 “ A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be avai ...
- 0040 Java学习笔记-多线程-线程run()方法中的异常
run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...
- jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.
jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...
随机推荐
- AIApe问答机器人Scrum Meeting 4.27
Scrum Meeting 3 日期:2021年4月27日 会议主要内容概述:汇报两日工作. 一.进度情况 组员 负责 两日内已完成的工作 后两日计划完成的工作 工作中遇到的困难 李明昕 后端 Tas ...
- TCP/IP简述
一.TCP/IP简述 TCP/IP从字面异议看起来是指TCP和IP两种协议,实际上,它只是利用IP进行通信时必须用到的协议群的统称.具体的来说,IP或ICMP.TCP或UDP.Telnet或FTP.以 ...
- linux下文件后面带~
之前发现有时候在命令行ls会看到一些文件后面带有-,而这些文件的名字和我们文件夹中的某些文件是一模一样的文件,在文件夹中没发现就很大胆地删掉了也没是,一直没管,觉得是什么临时复制的文件或者隐藏文件.今 ...
- C++ 入门到进阶 学习路线
前言 学习这件事不在乎有没有人教你,最重要的是在于你自己有没有觉悟和恒心. -- 法布尔 简介 随着互联网及互联网+深入蓬勃的发展,经过40余年的时间洗礼,C/C++俨然已成为一门贵族语言,出色的性能 ...
- (2)Canal管理后台在linux环境上部署
1.背景 canal-admin设计为canal组件提供了配置管理.节点运维等功能的WebUI操作界面,方便用户快速操作. 2.前期准备 先到官网下载个canal.admin组件:也可以输入命令下载: ...
- 组件通过props属性传值
组件之间的传值 组件是一个单独功能模块的封装,有属于自己的data和methods,一个组件的 data 选项必须是一个函数 为什么必须是函数:因为只有当data是函数时,不同实例调用同一个组件时才会 ...
- 远程连接linux | Xshell和Xftp下载安装
为什么需要远程登录linux 公司开发时候, 具体的情况是这样的: Linux 一般作为服务器使用,而服务器一般放在机房,你不可能在机房操作你的 Linux 服务器.这时我们就需要远程登录到Linux ...
- .NET Conf 2021 正在进行中,带你看一看微软带来了什么内容
今年最大的.NET活动正在进行, 可以通过Channel9 https://channel9.msdn.com/Events/dotnetConf/2021 看具体的Session .微软和社区一直在 ...
- sqlalchemy create single table
User.__table__.drop(engine) User.__table__.create(engine) https://stackoverflow.com/a/45287771/80250 ...
- M1配置php环境完整版(用于M1芯片的Mac中,php开发环境,比如wordpress、"或wp"、emlog pro、typecho等本地开发环境的配置)
因为macbook发布的M1是基于arm架构的,导致很多软件在短时间没无法兼容,其中包括php的很多集成开发环境软件.于是需要手动配置.网上的信息也是零七八碎,故制作了这个完整的教程. 本教程基于的m ...