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 mmtransmission 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 11to 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−1if 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
做了洛谷的这个题就发现这个题是水题一个
勿忘打铁耻辱,在做一次,完全是自己思考
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,m,c,d,e;
vector<int>G[N];
vector<ll>val[N];
bool vis[N];
ll dis[N];
struct node{
int id;
ll w;
bool operator <(const node &o) const {
return o.w<w;
}
};
bool bfs(ll mx)
{
priority_queue<node>que;
memset(dis,0x3f3f3f3f3f3f3f,sizeof(dis));
memset(vis,0,sizeof(vis));
dis[1]=0;
que.push({1,0});
while(que.size()){
node now=que.top();que.pop();
if(vis[now.id]) continue;
vis[now.id]=1;
for(int i=0;i<G[now.id].size();++i){
int v=G[now.id][i];
ll w=val[now.id][i];
if(w>mx*d)continue;
if(dis[v]>dis[now.id]+1){
dis[v]=dis[now.id]+1;
que.push({v,dis[v]});
}
}
}
//printf("dis[n]:%lld\n",dis[n]);
if(dis[n]<=1ll*e*mx) return 1;
return 0;
}
int main()
{
scanf("%d%d",&n,&m);
scanf("%d%d%d",&c,&d,&e);
for(int i=1;i<=m;++i){
int u,v;ll w;
scanf("%d%d%lld",&u,&v,&w);
G[u].push_back(v);
G[v].push_back(u);
val[u].push_back(w);
val[v].push_back(w);
}
int l=0,r=1e9;
int ans=-1;
while(l<=r){
ll mid=l+r>>1;
if(bfs(mid)){
r=mid-1;
ans=mid;
}
else l=mid+1;
}
if(ans==-1) printf("-1\n");
else
printf("%lld\n",1ll*ans*c);
}