Travel

There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. Each planet is connected to other planets through some transmission channels. There are mm 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 11 level each time, and the cost is cc. Each upgrade will increase the transmission distance by dd and the number of transmissions channels by ee 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 00-level spacecraft with transmission distance of 00 and transmission number of 00. Alice wants to know how much it costs at least, in order to transfer from planet 11 to planet nn.

Input

Each test file contains a single test case. In each test file:

The first line contains nn, mm, indicating the number of plants and the number of transmission channels

The second line contains cc, dd, ee, representing the cost, the increased transmission distance, and the increased number of transmissions channels of each upgrade, respectively.

Next mm lines, each line contains u,v,wu,v,w, meaning that there is a transmission channel between uu and vv with a length of ww.

(2 \le n\le 10^5, n - 1 \le m \le 10^5,1 \le u,v \le n ,1 \le c,d,e,w \le 10^5)(2≤n≤105,n−1≤m≤105,1≤u,v≤n,1≤c,d,e,w≤105)

(The graph has no self-loop , no repeated edges , and is connected)

Output

Output a line for the minimum cost. Output -1−1 if she can't reach.

样例输入复制

5 7
1 1 1
1 2 1
1 3 5
1 4 1
2 3 2
2 4 5
3 4 3
3 5 5

样例输出复制

5

二分+最短路。

代码:

 //M-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
const int inf=0x3f3f3f3f;
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second namespace IO{
char buf[<<],*S,*T;
inline char gc(){
if (S==T){
T=(S=buf)+fread(buf,,<<,stdin);
if (S==T)return EOF;
}
return *S++;
}
inline int read(){
int x; bool f; char c;
for(f=;(c=gc())<''||c>'';f=c=='-');
for(x=c^'';(c=gc())>=''&&c<='';x=(x<<)+(x<<)+(c^''));
return f?-x:x;
}
inline long long readll(){
long long x;bool f;char c;
for(f=;(c=gc())<''||c>'';f=c=='-');
for(x=c^'';(c=gc())>=''&&c<='';x=(x<<)+(x<<)+(c^''));
return f?-x:x;
}
}
using IO::read;
using IO::readll; int n,m;
int c,d,e;
int head[maxn<<],cnt;
int dis[maxn],pathmin,edgemin;
bool vis[maxn];
priority_queue<pii,vector<pii>,greater<pii> > q; struct Edge{
int u,v,w;
}path[maxn]; struct node{
int to,next,w;
}edge[maxn<<]; void init()
{
memset(head,-,sizeof head);
memset(edge,,sizeof edge);
memset(vis,,sizeof vis);
memset(dis,inf,sizeof dis);
cnt=;
} void add(int u,int v,int w)
{
edge[cnt].to=v;
edge[cnt].w=w;
edge[cnt].next=head[u];
head[u]=cnt++;
} void dijkstra(int s)
{
dis[s]=;
q.push(mp(,s));
while(!q.empty()){
int u=q.top().se;q.pop();
vis[u]=true;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].to;
int w=edge[i].w;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push(mp(dis[v],v));
}
}
}
} void solve()
{
pathmin=inf;edgemin=inf;
int l=,r=1e5;
while(l<=r){
int mid=(l+r)>>;
init();
for(int i=;i<=m;i++){
if(path[i].w<=mid){
add(path[i].u,path[i].v,);
add(path[i].v,path[i].u,);
}
}
dijkstra();
if(dis[n]<=mid){
r=mid-;
if(edgemin>mid){
edgemin=mid;
pathmin=dis[n];
}
else if(edgemin==mid){
pathmin=min(pathmin,dis[n]);
}
}
else{
l=mid+;
}
}
} int main()
{
n=read();m=read();
// scanf("%d%d",&n,&m);
c=read();d=read();e=read();
// scanf("%d%d%d",&c,&d,&e);
for(int i=;i<=m;i++){
path[i].u=read();path[i].v=read();path[i].w=read();
// scanf("%d%d%d",&path[i].u,&path[i].v,&path[i].w);
}
solve();//路径的最大边权
edgemin=edgemin/d+(edgemin%d==? :);
pathmin=pathmin/e+(pathmin%e==? :); //路径条数
printf("%lld\n",1ll*max(edgemin,pathmin)*c);
}
*/
/* 5 7
1 1 1
1 2 3
1 3 4
1 4 4
2 3 2
2 4 5
3 4 1
3 5 3 3 /*
//M-HY学长的代码orz
//二分+最短路spfa
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std; typedef long long ll;
const int N = 200010, mod = 1e9+7, M = 300005; ll addCost, addDist, addNum; int n, m, fa[N], head[N], tot2;
pair<ll, pair<int ,int > > e1[M];
struct Edge{ int to, next; ll w; } e[M];
void Init() {
tot2=0;
memset(head, -1, sizeof(head));
}
void Addedge(int u, int v, ll w) {
e[tot2]={v, head[u], w}; head[u]=tot2++;
e[tot2]={u, head[v], w}; head[v]=tot2++;
} queue<int > Q;
bool inQ[N];
ll dis[N];
bool spfa(int mid)
{
memset(inQ, false, sizeof(inQ));
memset(dis, INF, sizeof(dis));
dis[1] = 0;
Q.push(1);
inQ[1] = true;
ll mostDist = addDist * mid;
ll mostNum = addNum * mid;
while (!Q.empty())
{
int u = Q.front(); //cout << u << " " << dis[u] << " ---- \n";
Q.pop();
for (int i = head[u]; i != -1; i = e[i].next)
{
if (e[i].w > mostDist)
continue;
if (dis[e[i].to] > dis[u] + 1)
{
dis[e[i].to] = dis[u] + 1;
if (!inQ[e[i].to])
{
Q.push(e[i].to);
inQ[e[i].to] = true;
}
}
}
inQ[u] = false;
}
return dis[n] != INF && dis[n] <= mostNum;
} int main()
{
scanf("%d %d", &n, &m);
scanf("%lld %lld %lld", &addCost, &addDist, &addNum);
Init();
for (int i = 1; i <= m; ++ i)
{
scanf("%d %d %lld", &e1[i].second.first, &e1[i].second.second, &e1[i].first);
Addedge(e1[i].second.first, e1[i].second.second, e1[i].first);
} //cout << 1111 << endl;
// 二分
int l = 0, r = N, mid, ans = INF;
while (l <= r)
{
mid = (l + r) / 2;
if (spfa(mid))
ans = mid, r = mid -1;
else
l = mid + 1;
//cout << l << " " << r << " " << ans << endl;
}
if (ans == INF)
printf ("-1\n");
else
printf ("%lld\n", addCost * ans); return 0;
}
*/

计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛的更多相关文章

  1. 计蒜客 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  ...

  2. 计蒜客 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 ...

  3. 计蒜客 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 ...

  4. 计蒜客 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 ...

  5. The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And

    链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...

  6. 计蒜客T2202 数三角形(提高组2017模拟赛(三)day2T3) LZOJ3878攻略

    今天模拟赛考了一道计蒜客NOIP2017模拟赛(三)day2T3的数三角形,原题链接 https://nanti.jisuanke.com/t/T2202 ,LZOJ3878攻略.场上想了很久都没转化 ...

  7. 2019计蒜客信息学提高组赛前膜你赛 #2(TooYoung,TooSimple,Sometimes Naive

    计蒜客\(2019CSP\)比赛第二场 巧妙爆零这场比赛(我连背包都不会了\(QWQ\) \(T1\) \(Too\) \(Young\) 大学选课真的是一件很苦恼的事呢! \(Marco\):&qu ...

  8. 计蒜客模拟赛5 D2T1 成绩统计

    又到了一年一度的新生入学季了,清华和北大的计算机系同学都参加了同一场开学考试(因为两校兄弟情谊深厚嘛,来一场联考还是很正常的). 不幸的是,正当老师要统计大家的成绩时,世界上的所有计算机全部瘫痪了. ...

  9. [计蒜客] 矿石采集【记搜、Tarjan缩点+期望Dp】

    Online Judge:计蒜客信息学3月提高组模拟赛 Label:记搜,TarJan缩点,树状数组,期望Dp 题解 整个题目由毫无关联的两个问题组合成: part1 问题:对于每个询问的起点终点,求 ...

随机推荐

  1. 定时任务-Windows任务

    定时任务-Windows任务   什么是windows任务 windows系统自带一个任务管理组件.可以执行自己写的程序,发送电子邮件(需要邮件服务器),显示消息(就是桌面弹出一个窗口).用的最多的就 ...

  2. command injection命令注入

    命令注入 是指程序中有调用系统命令的部分,例如输入ip,程序调用系统命令ping这个ip.如果在ip后面加一个&&.&.|.||命令拼接符号再跟上自己需要执行的系统命令 在pi ...

  3. 2. ES6基础-let和const命令

    目录 1. let命令 1.1 用法 1. 2 不存在变量提升 1.3 区域绑定 1.4 不允许重复声明 2. const命令 2.1 用法 2.2 与let类似的特性 2.3 const本质 2.4 ...

  4. 水泥caement单词

    Caement英语单词,翻译为:水泥 中文名:水泥 外文名:caement 目录 释义 caement 读音:英 [sɪˈment] 美 [sɪˈmɛnt] Noun名词. 水泥; caement在英 ...

  5. CentOS 7 - 以root身份登入Gnome

    新版的7.0很多资料没有,为了安全,linux是禁止root登录到桌面,但为了方便又想用root登录到桌面,在网上找了找,基本上都是这这一篇: http://shaoguangleo.blog.163 ...

  6. ResourceDictionary文件排序方法

    默认生成的ResourceDictionary文件是根据主键的hashcode排序生成的,如果想按主键排序生成是不可能的. 可以使用Xml的处理方法来生成ResourceDictionary文件. 1 ...

  7. MySQL Others--约束(Constraint)示例

    ENUM约束 --使用ENUM来限制用户输入 CREATE TABLE Student ( StudentID INT AUTO_INCREMENT PRIMARY KEY, ClassID INT, ...

  8. 申请软件著作权,wps显示代码行号功能

    申请软件著作权时,要提交代码. 格式要求,每页不少于50行,怎么设置格式,保障每页至少50行呢? 选择[页面布局]---[行号]--[每页重编行号]即可显示出来,根据显示出来的行号,调整行距等格式即可 ...

  9. http,socket,进程通信,网络通信(1)

    众所周知,网络通信本质上就是进程间通信,进程间通信有以下常见的通信方式: 1,管道pipe:管道是一种半双工的通信方式,数据只能单向流动,而且只能在具有亲缘关系的进程间使用,进程的亲缘关系通常指父子进 ...

  10. mysql数据库查询缓存总结

    概述 查询缓存(Query Cache,简称QC),存储SELECT语句及其产生的数据结果.闲来无事,做一下这块的总结,也做个备忘! 工作原理 查询缓存工作原理如下: 缓存SELECT操作的结果集和S ...