题目链接:https://vjudge.net/problem/Gym-101490E
题意:给你一个图,首先让你求一个最短路s,给你一个x,让你找一条新的路径,这条路径的总长度不能超过s*(1+x%),且这条路径上的所有边权的最大值最小
解析:先跑一次最短路,这是没毛病的,那么接下来怎么求解第二个问题呢,如果告诉你这条路径的阈值,让你找一条路径,肯定是可以找的,那么就可以通过二分答案来找这条路径,如果这条路径的总和小于要求,那么r=mid,这样做下去就可以出来了
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int maxn = 1e5+100;
typedef long long ll;
struct node
{
int to,c;
node() {}
node(int _to,int _c)
{
to = _to;
c = _c;
}
bool operator < (const node &b)const
{
return c>b.c;
}
};
vector<node> G[maxn];
ll d[maxn];
ll dj(ll mid,int s,int n)
{
priority_queue<node>q;
fill(d+1,d+n+1,inf);
d[s] = 0;
q.push(node(s,0));
while(!q.empty())
{
node now = q.top();
q.pop();
int u = now.to;
if(d[u]<now.c)
continue;
for(int i=0;i<(int)G[u].size();i++)
{
node v = G[u][i];
if(d[v.to]>d[u]+v.c && v.c<=mid)
{
d[v.to] = d[u]+v.c;
q.push(node(v.to,d[v.to]));
}
}
}
return d[n];
}
int main(void)
{
int n,m,x;
scanf("%d %d %d",&n,&m,&x);
for(int i=0;i<m;i++)
{
int x,y,c;
scanf("%d %d %d",&x,&y,&c);
G[x].push_back(node(y,c));
}
ll l = 1,r = 1e9;
ll res = dj(inf,1,n);
ll ans = inf;
res = res*(100+x);
for(int i=0;i<200;i++)
{
ll mid = (l+r)/2;
ll tmp = dj(mid,1,n);
tmp = tmp*100LL;
if(tmp<=res)
{
ans = min(mid,ans);
r = mid;
}
else
l = mid;
}
printf("%I64d\n",ans);
return 0;
}