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. ExtractFileDir 与 ExtractFilePath 的区别

    ExtractFileDir 从文件名中获取目录名(文件不在根目录下时取得的值后没有“/”,在根目录时一样,都是盘符,例如“C:/”) ExtractFilePath 从文件名中获取路径名(文件不在根 ...

  2. 常用正则表达式和一些demo

    一.校验数字的表达式 数字:^[0-9]*$ n位的数字:^\d{n}$ 至少n位的数字:^\d{n,}$ m-n位的数字:^\d{m,n}$ 零和非零开头的数字:^(0|[1-9][0-9]*)$ ...

  3. 关于zynq系列板卡设计VREFP_0参考电压的疑问及解答

    使用板卡:Z-turn Board 芯片:Xilinx Zynq-7010/7020处理器 有工程师在试用zynq系列Z-turn Board时提出:在原理图P3页 Bank0上VREFP_0端接地的 ...

  4. JAVA项目之增删改查

    public class ProductDao { // 查询所有商品 // BeanListHandler查询所有商品 public List<Product> getAll() thr ...

  5. Redis_初识

    一.简介 Redis(Remote Dictionary Server)本质上是一个Key-Value类型的内存数据库,整个数据库统统加载在内存当中进行操作,定期通过异步操作吧数据库flush到硬盘上 ...

  6. Solr基础知识一(安装配置)

    最近接到需求,要修改网站内的搜索规则,就去看了下Solr的资料.现在做完需求了,回来做一些笔记,方便以后查找. 一.安装 1.1 配置JDK JDK下载地址为:https://www.oracle.c ...

  7. Python包模块化调用方式详解

    Python包模块化调用方式详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一般来说,编程语言中,库.包.模块是同一种概念,是代码组织方式. Python中只有一种模块对象类型 ...

  8. HTML&CSS基础-html标签的实体

    HTML&CSS基础-html标签的实体 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HTML源代码 <!DOCTYPE html> <html&g ...

  9. 测试MongoDB的自动分片

    MongoDB的自动分片: test库分片配置: db.shards.find(){ "_id" : "shard0000", "host" ...

  10. aspose将word转pdf时乱码,或者出现小方框问题

    通常来讲,出现这种问题一般是因为Linux服务器没有安装中文字体  查看Linux目前的所有字体 fc-list #查看Linux目前的所有中文字体 fc-list :lang=zh #将window ...