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 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...
随机推荐
- redis node 常用命令
命令窗口 flushall //清空全库 keys * //查看所有 HMSET user1 name liujinyu age 25 //哈希 添加多个值 HSET user1 sex man // ...
- 使用mybatis框架实现带条件查询-单条件
之前我们写的查询sql都是没有带条件的,现在来实现一个新的需求,根据输入的字符串,模糊查询用户表中的信息 UserMapper.xml UserMapper.java 与jdbc的比较: 编写测试方法 ...
- 微软安全技术Shim
Shim是微软系统中一个小型函数库,用于透明地拦截API调用,修改传递的参数.自身处理操作.或把操作重定向到其他地方.Shim主要用于解决遗留应用程序在新版Windows系统上的兼容性问题,但Shim ...
- [RN] React Native 幻灯片效果 Banner
[RN] React Native 幻灯片效果 Banner 1.定义Banner import React, {Component} from 'react'; import {Image, Scr ...
- [Gradle] 发布 library 到本地 maven 仓库
Java Library // publish_local_java.gradle apply plugin: 'maven-publish' publishing { publications { ...
- Freemarker的简单demo
第一步.导入依赖 <dependency> <groupId>org.freemarker</groupId> <artifactId>freemark ...
- 对5月13号中BaseDao方法进行优化改造,更接近于框架的编写
/* * 通用查询.更新升级版 * */ public class BaseDao2 { static { try { Class.forName(ConfigUtil.getValue(" ...
- java JBDC操作
类似:c# 里面的ado.net 增删改查,动手做Demo (当然实际企业开发很少用这种方式 ). ps:以前从一开始 搞ssm spring Boot spring Mvc 什么都懂一点.什么都 ...
- hdu1237 简单计算器[STL 栈]
目录 题目地址 题干 代码和解释 参考 题目地址 hdu1237 题干 代码和解释 解本题时使用了STL 栈,要记得使用#include<stack>. 解本题时使用了isdigit()函 ...
- 2015-2016-2《Java程序设计》团队博客4
一.类结构图 这一周将所有的类都进行了实现,以下是这周实现的类图: 二.项目进展 目前已经将所有代码都编写完成,正在进行整体测试.虽然期间遇到了一些问题,但我们一起进行了讨论,并查找了 ...