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 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...
随机推荐
- screen对象及属性(availWidth、availHeight)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- php正则表示中的元字符
元字符 抛出问题: \d 代表匹配一个字符.而我现在想要匹配十个八个,任意多个数字肿么办? 这个时候我们就要用到元字符.在使用原子的时候,发现只能够匹配一个字符,可是要匹配多个字符就出现了问题.大理石 ...
- mysql 查询账户
查询 mysql 的存在的账户 >select user,host,password from mysql.user; # 可以查询涉及到user. host 链接权限.密码加密文件.
- 微信小程序根据状态换图
在index.wxml中添加图片 <image bindtap="click" src="{{show?'/images/.png':'/images/.png'} ...
- [golang]Go常见问题:# command-line-arguments: ***: undefined: ***
今天遇见一个很蛋疼的问题,不知道是不是我配置的问题,IDE直接run就报错. 问题描述 在开发代码过程中,经常会因为逻辑处理而对代码进行分类,放进不同的文件里面:像这样,同一个包下的两个文件,点击id ...
- x32下的DLL隐藏
原理主要就是PEB 中模块断链. 这里整理下代码.原理可以看下另一篇我写的帖子. https://www.cnblogs.com/iBinary/p/9601860.html // dllmain.c ...
- LAMP架构介绍
介绍一下LAMP架构 LMAP即Linux+Apache+Mysql/MariaDB+Perl/PHP/Python的首字母缩写.这是一组常用来搭建动态网站或者服务器的开源软件.它们本身都是各自独立的 ...
- element-ui里面的table插入多张图片
<el-form-item label="身份证正反面" label-width="120px"> <section v-if="t ...
- 配置docker阿里云加速器
1. 安装/升级Docker客户端 推荐安装1.10.0以上版本的Docker客户端,参考文档 docker-ce 2. 配置镜像加速器 针对Docker客户端版本大于 1.10.0 的用户 您可以通 ...
- 在js中添加HTML类样式
有时候需要给元素添加类样式,但又要保留之前的类,可以使用element.classList.add("类名");