2019 acm icpc西安邀请赛 M Travel

Travel 

  •  22.85%
  •  1000ms
  •  262144K

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

二分升级次数,check能否走到 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=2e5+5;
const int inf=0x3f3f3f3f;
std::vector<pair<ll,ll> > G[maxn];
ll dis[maxn];int vis[maxn],cnt[maxn],n,m,c,d,e;
struct node
{
	ll dis,pos;
	bool operator<(const node& x)const
	{
		return dis>x.dis;
	}
};
priority_queue<node>q;
inline int dijkstra(int k)
{
	memset(vis,0,sizeof vis);
    memset(cnt,inf,sizeof cnt);
    memset(dis,inf,sizeof dis);
    dis[1]=cnt[1]=0;
    q.push((node){0,1});
    while(!q.empty())
    {
        node x=q.top();q.pop();
        ll u=x.pos;
        if(vis[u])continue;
        vis[u]=1;
        for(auto &it:G[u])
        {
        	if(dis[it.first]>=dis[u]+it.second&&it.second<=k*d)
        	{
        		dis[it.first]=dis[u]+it.second;
        		cnt[it.first]=min(cnt[it.first],cnt[u]+1);
        		q.push((node){dis[it.first],it.first});
        	}
        }
    }
    if(dis[n]<inf && cnt[n]<=k*e) return 1;
    return 0;
}
int main()
{
	scanf("%d%d",&n,&m);scanf("%d%d%d",&c,&d,&e);
	for(int i=0;i<m;i++)
	{
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		G[u].emplace_back(v,w);
		G[v].emplace_back(u,w);
	}
	int l=1,r=5000;
	while(l<r)
	{
		int m=(l+r)>>1;
		if(dijkstra(m)) r=m;
		else l=m+1;
	}
	if(dijkstra(r))printf("%lld\n",1LL*r*c);
	else printf("-1\n");
	return 0;
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值