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

  1. Bubble Cup 8 finals G. Run for beer (575G)

    题意: 给定一个带权无向图,每条边的代价为边权/当前速度,每次到达一个新节点,速度都会除以10. 求0号点到n-1号点的最小代价,如果多解输出点数最少的解,输出代价.路径点数.路径经过的点. 1< ...

  2. Solution -「CF 575G」Run for beer

    \(\mathcal{Description}\)   Link.   给定 \(n\) 个点 \(m\) 条边的无向图,边有边权,一个人初始速度为 \(1\),每走一条边速度 \(\div10\), ...

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

  4. DotNet Run 命令介绍

    前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...

  5. 布里斯班Twilight Bay Run半程马拉松

    自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...

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

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

  8. 0040 Java学习笔记-多线程-线程run()方法中的异常

    run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...

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

随机推荐

  1. 【原创】Linux v4l2框架分析

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...

  2. Scrum Meeting 0425

    零.说明 日期:2021-4-25 任务:简要汇报两日内已完成任务,计划后两日完成任务 一.进度情况 组员 负责 两日内已完成的任务 后两日计划完成的任务 qsy PM&前端 完成登录.注册A ...

  3. Python:Ubuntu上使用pip安装opencv-python出现错误

    Ubuntu 18.04 上 使用 pip 安装 opencv-python,出现的错误如下: 1 ~$: pip install opencv-python -i https://pypi.tuna ...

  4. 全志Tina_dolphin播放音视频裸流(h264,pcm)验证

    最近在验证tina对裸流音视频的支持,主要指h264视频裸流及pcm音频裸流. 在原始sdk中有针对很多video和audio类型的parser,但就是没有找到pcm和h264的parser,所以需要 ...

  5. Luogu P2149 [SDOI2009]Elaxia的路线 | 图论

    题目链接 题解: 题面中给了最简洁清晰的题目描述:"求无向图中,两对点间最短路的最长公共路径". 对于这个问题我们可以先考虑图中的哪些边对这两对点的最短路产生了贡献. 比如说下面这 ...

  6. NOIP模拟88(多校21)

    前言 对于这套题的总体感觉就是难,然后就是自己很菜... 对于 T1 考试时只会一个最垃圾的背包,考完之后对于思路这一块也不是很顺利,大概这就是薄弱的地方吧. 然后 T2 是比较简单的一道题了,但是考 ...

  7. nohup java -jar xx.jar & ,关闭窗口后退出进程

    nohup java -jar dw-report..jar > dw-report.log  & 自动退出命令在后台运行 xx.jar程序 明明已经加了"&" ...

  8. svg的animate动画动态加载删除遇到删除animate后再次加载的animate动画没有效果问题

    svg上有多个圆圈,当选中特定圆圈后给其加上animate动画效果,并把其他圆圈的animate效果去除. 第一次选择一个点实现动画效果完全达到效果,因为是第一次所以不需要把其他圆圈的animate子 ...

  9. request/response解决中文乱码!!!

    Request中文乱码问题以及解决方案 补充三个知识点: Get是URL解码方式.默认解码格式是Tomcat编码格式.所以URL解码是UTF-8,覆盖掉了request容器解码格式 Post是实体内容 ...

  10. spring security之 默认登录页源码跟踪

    spring security之 默认登录页源码跟踪 ​ 2021年的最后2个月,立个flag,要把Spring Security和Spring Security OAuth2的应用及主流程源码研究透 ...