2019 西安邀请赛 M
Problem Description
There are n planets in the MOT galaxy, and each planet has a unique number from ∼n. Each planet is connected to other planets through some transmission channels. There are m transmission channels in the galaxy. Each transmission channel connects two different planets, and each transmission channel has a length.
The residents of the galaxy complete the interplanetary voyage by spaceship. Each spaceship has a level. The spacecraft can be upgraded several times. It can only be upgraded level each time, and the cost is c. Each upgrade will increase the transmission distance by d and the number of transmissions channels by e to the spacecraft. The spacecraft can only pass through channels that are shorter than or equal to its transmission distance. If the number of transmissions is exhausted, the spacecraft can no longer be used.
Alice initially has a -level spacecraft with transmission distance of and transmission number of . Alice wants to know how much it costs at least, in order to transfer from planet to planet n. Input
Each test file contains a single test case. In each test file:
The first line contains n, m, indicating the number of plants and the number of transmission channels.
The second line contains c, d, e, representing the cost, the increased transmission distance, and the increased number of transmissions channels of each upgrade, respectively.
Next m lines, each line contains u,v,w, meaning that there is a transmission channel between u and v with a length of w.(≤n≤, n-≤m≤,≤u,v≤n ,≤c,d,e,w≤)
(The graph has no self-loop , no repeated edges , and is connected) Output
Output a line for the minimum cost. Output - if she can’t reach. Sample Input Sample Output 题意
有n个点,编号从1到n,有m条边,每条边有一个长度w。
Alice有一艘飞船,Alice可以给它升级很多次(无限),每升级一次需要花费c,升级一次之后飞船单次可飞行距离增加d,可飞行次数增加e。如果飞船需要飞过一条边,就需要满足单次可飞行距离≥这条路的长度同时可飞行次数不为0。
现在Alice在编号为1的点,她的飞船为0级,单次可飞行距离和可飞行次数都为0,请你求出最小的花费使得Alice可以到达n点,如果不能到达n则输出-。
// 二分更新次数
//无环无向图且联通 ,就是树
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define N 100100
#define inf 1e12
int n,m,cnt;
ll c,d,E;ll u,v,w;
ll head[N*];
ll dis[N],num[N];
struct Node{
ll u,v,w,nex;
Node(){
}
Node(ll u,ll v,ll w,ll nex):u(u),v(v),w(w),nex(nex){}
}e[N*];
void init()
{
cnt = ;
memset(head,-,sizeof(head));
}
void add(ll u,ll v,ll w)
{
e[cnt].u=u;e[cnt].v=v;e[cnt].w=w;
e[cnt].nex = head[u];head[u]=cnt++;
}
bool check(ll mid)
{
//假设在起点就已经更新了mid次,验证mid是否满足条件
priority_queue<P,vector<P>,greater<P> >q;
fill(dis,dis+n+,inf);fill(num,num+n+,inf);
dis[]=num[]=;
q.push(P(,));
while(!q.empty())
{
P tmp =q.top();q.pop();
ll u=tmp.second;
if(dis[u]<tmp.first) continue;
for(ll i=head[u];i!=-;i=e[i].nex){
ll v=e[i].v;
if(dis[v]>dis[u]+e[i].w&&e[i].w<=mid*d){
dis[v] = dis[u] +e[i].w;
num[v] = min(num[v],num[u]+);//更新出最小的
q.push(P(dis[v],v));
}
}
}
return num[n]<=mid*E;//1: 可以走到n 2 :走过的路径数目满足条件
}
int main()
{
init();
scanf("%d%d",&n,&m);
scanf("%lld%lld%lld",&c,&d,&E);
for(int i =;i<m;i++) {
scanf("%lld%lld%lld",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
ll l =,r=,res,mid;
while(l<=r)
{
mid = (l+r)>>;
if(check(mid)) {
res = mid;r=mid-;
}
else{
l=mid+;
}
}
printf("%lld\n",res*c);
return ;
}
//code2
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define N 100100
#define inf 1e12
int n,m,cnt;
ll c,d,E;ll u,v,w;
ll head[N*];
bool vis[N];
struct Node{
ll u,v,w,nex;
Node(){
}
Node(ll u,ll v,ll w,ll nex):u(u),v(v),w(w),nex(nex){}
}e[N*];
void init()
{
cnt = ;
memset(head,-,sizeof(head));
}
void add(ll u,ll v,ll w)
{
e[cnt].u=u;e[cnt].v=v;e[cnt].w=w;
e[cnt].nex = head[u];head[u]=cnt++;
}
bool check(ll mid)
{
/*
由于是树,那么任意两点的路径唯一
只需要判断在 当前的次数下,在满足单次可飞行距离≥这条路的长度下,凭借的当前可用步数能走到n吗
*/
memset(vis,,sizeof(vis));//每次都是重新来
ll num =mid*E;ll dd = mid*d;
//假设在起点就已经更新了mid次,验证mid是否满足条件
queue<P>q ;
q.push(P(,num)); //first :当前 到达的点 second :还余下的可走的步数
vis[]=;
while(!q.empty())
{
P tmp =q.front();q.pop();
ll u = tmp.first;ll cnt=tmp.second;
if(u==n) return ;
else{
for(ll i=head[u];i!=-;i=e[i].nex){
ll v=e[i].v;
if(!vis[v]&&e[i].w<=dd&&cnt>){
vis[v] = ;
q.push(P(v,cnt-));
}
}
}
}
return ;
}
int main()
{
init();
scanf("%d%d",&n,&m);
scanf("%lld%lld%lld",&c,&d,&E);
for(int i =;i<m;i++) {
scanf("%lld%lld%lld",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
ll l =,r=,res,mid;
while(l<=r)
{
mid = (l+r)>>;
if(check(mid)) {
res = mid;r=mid-;
}
else{
l=mid+;
}
}
printf("%lld\n",res*c);
return ;
}
2019 西安邀请赛 M的更多相关文章
- 2019 西安邀请赛 D
//n件物品,m种关系,(有关系的2个不能在同一组) //把所有物品分为2组,希望最后2组的差值尽可能小,输出较大者 /* 二分图涂色+可行性(01)背包 dp[i] =1表示 最后差值为i可行 建图 ...
- ACM-ICPC 2019 西安邀请赛 D.Miku and Generals(二分图+可行性背包)
“Miku is matchless in the world!” As everyone knows, Nakano Miku is interested in Japanese generals, ...
- 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛
Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered ...
- 2019南昌邀请赛网络预选赛 M. Subsequence
传送门 题意: 给出一个只包含小写字母的串 s 和n 个串t,判断t[i]是否为串 s 的子序列: 如果是,输出"YES",反之,输出"NO": 坑点: 二分一 ...
- 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛
Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
- 计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛
Angel's Journey “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on ...
- 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛
Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...
- The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And
链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...
随机推荐
- python 格式化输出%s %f %d
格式说明由%和格式字符组成,如%f,它的作用是将数据按照指定的格式输出.格式说明是由“%”字符开始的. 1.整型输出%d print 'my age is %d'% (26) 说明:%d相当于是一个占 ...
- go 学习 (五):goroutine 协程
一.goroutine 基础 定义 使用者分配足够多的任务,系统能自动帮助使用者把任务分配到 CPU 上,让这些任务尽量并发运作,此机制在Go中称作 goroutine goroutine 是 Go语 ...
- [ARIA] Create an Accessible Tooltip on a Text Input
Here we use HTML and CSS to create a stylish yet semantic tooltip on a form input. I am using aria-d ...
- SQL Server 中PAGELATCH_x和PAGEIOLATCH_x解析
0.参考文献 Microsoft SQL Server企业级平台管理实践 第11章 Buffer Latch Timeout的解析 什么是PAGELATCH和PAGEIOLATCH 1.PAGELAT ...
- 55、Spark Streaming:updateStateByKey以及基于缓存的实时wordcount程序
一.updateStateByKey 1.概述 SparkStreaming 7*24 小时不间断的运行,有时需要管理一些状态,比如wordCount,每个batch的数据不是独立的而是需要累加的,这 ...
- c博客作业01——顺序 分支结构
本章学习总结 1.1 学习内容总结 ·学习switch分支的使用,switch后加括号(),括号内填一个变量或字符 如 switch (a) { case 2: case 3: default: } ...
- JVM内存的划分
JVM内存的划分有五片: 1. 寄存器: 2. 本地方法区: 3. 方法区: 4. 栈内存: 5. 堆内存.
- 工作发狂:Mybatis 中$和#千万不要乱用!
阅读本文大概需要 2.2 分钟. 作者:程序猿的内心独白 开头 这是一次代码优化过程中发现的问题,在功能优化后发现部分数据查不到出来了,问题就在于一条sql上的#和$. 下图为两条sql: 从图上可以 ...
- 循环(for,while,until)与循环控制符(break,continue)
一.for循环 第一种风格 for ((;;;))(类似C语言风格) do command done 例子:for ((i=0;i<10;i++)) do echo $i done 第二种风 ...
- EF 调试跟踪生成的SQL语句
IQueryable query = from x in appEntities select x; var sql = ((System.Data.Objects.ObjectQuery)query ...