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字符的表示格式
%% 百分号标记 #就是输出一个% %c 字符及其ASCII码%s 字符串%d 有符号整数(十进制)%u 无符号整数(十进制)%o 无符号整数(八进制)%x 无符号整数(十六进制)%X 无符号整数(十 ...
- gin内置验证器使用
gin内置验证器使用 func TopicUrl(f1 validator.FieldLevel) bool { return true //返回true表示验证成功 } func main(){ r ...
- 持续集成学习7 jenkins自动化代码构建
一.整体功能 1.触发上下游构建 2.我们在触发一个job的时候顺便丢一些参数过去,这些参数有可能是我这次编译过程中产生的一些地址,版本号或动态的一些东西丢到下游作为下游的构建参数 3.不同种类的视图
- hibernate之多对多关系
hibernate的多对多hibernate可以直接映射多对多关联关系(看作两个一对多) 下面我们拿三张表来做实例 t_book_hb t_book_category_hb(桥接表) t_catego ...
- redash oracle 数据源docker 镜像
redash 官方的docker 镜像是没有包含oracle的,需要我们自己添加,参考了一个docker 镜像进行了简单的修改 Dockerfile FROM redash/redash:7.0.0. ...
- JavaScript的入门篇
快速认识JavaScript 熟悉JavaScript基本语法 窗口交互方法 通过DOM进行网页元素的操作 学会如何编写JS代码 运用JavaScript去操作HTML元素和CSS样式 <!DO ...
- struct tcphdr
包含在/usr/src/linux/include/linux/tcp.h struct tcphdr { __be16 source; __be16 dest; __be32 seq; __be32 ...
- 玩家属性同步优化-脏数据标记(位运算、数组、stl之bitset)
把大神的帖子中一部分摘抄出来,结合自己写的位运算代码和循环代码(数组遍历)进行性能测试分析并给出结果. 摘自: https://www.gameres.com/827195.html 本文适用于所有脏 ...
- CSS — BEM 命名规范
推荐阅读: https://juejin.im/post/5b925e616fb9a05cdd2ce70d 1 什么是 BEM 命名规范 Bem 是块(block).元素(element).修饰符(m ...
- hdoj - 1864 最大报销额
Problem Description 现有一笔经费可以报销一定额度的发票.允许报销的发票类型包括买图书(A类).文具(B类).差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品 ...