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;
}
*/

最新文章

  1. == 与 equals 区别
  2. ASP------如何读取文件内容
  3. homework160809207刘兆轩
  4. Javaweb三大组件之过滤器filter
  5. sqlplus 远程oracle
  6. poj 1924 Paths on a Grid(组合数学)
  7. c#接口和new关键字和属性访问器基础收获
  8. fedora 设置命令别名
  9. socket编程之TCP/UDP
  10. JAX-RS REST 服务结果的自动封装
  11. 用IDEA/WebStrom 提交本地项目到Git/码云等
  12. Jmeter启动问题总结
  13. ROS_Kinetic_20 ROS基础补充
  14. springsession 实现session 共享
  15. [原]openstack-kilo--issue(十八) Error parsing template file: Template format version not found.
  16. Dotfuscator 使用图解教程
  17. 本地广播的简单示例 --Android开发
  18. MySQL 出现 Host is blocked because of many connection errors; unblock with &#39;mysqladmin flush-hosts&#39;
  19. ORA-00600: internal error code, arguments: [kgl-no-mutex-held]
  20. (转)MyBatis &amp; MyBatis Plus

热门文章

  1. 函数式接口java.util.function
  2. 获取当前URL地址和$_GET获取参数
  3. 4、线程池(摘自C#高级编程第7版)
  4. 单点logi,n
  5. Python 将中文、字母转成数字
  6. Python进阶(十四)----空间角度研究类,类与类之间的关系
  7. hadoop细节 -&gt; 持续更新
  8. webpack4引入JQuery的两种方法
  9. Linux基础-7.Linux网络基础设置
  10. echarts统计x轴区间的数值