DGME @ 2022-11-07 14:01:22
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
typedef long long LL;
typedef pair<LL,int> PII;
const int N = 1e4 + 10,M = 1e5 + 10;
const LL INF = LLONG_MAX / 3;
int h[N],e[M],ne[M],idx;
LL dist[N],f[N],w[M],b;
int n,m;
LL l,r;
bool st[N];
void add(int a,int b,LL c)
{
e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx ++;
}
bool check(LL x)
{
if(f[1] > x) return false;
priority_queue<PII,vector<PII>,greater<PII>> heap;
heap.push({0,1});
dist[1] = 0;
while(heap.size())
{
auto u = heap.top();heap.pop();
int v = u.second;
if(st[v]) continue;
st[v] = true;
for(int i = h[v];i != -1;i = ne[i])
{
int j = e[i];
if(f[j] <= x && dist[j] > dist[v] + w[i])
{
dist[j] = dist[v] + w[i];
heap.push({dist[j],j});
}
}
}
if(dist[n] <= b) return true;
return false;
}
int main()
{
cin >> n >> m >> b;
memset(h,-1,sizeof h);
for(int i = 1;i <= n;i ++) dist[i] = INF;
for(int i = 1;i <= n;i ++)
{
cin >> f[i];
r = max(r,f[i]);
}
l = max(f[1],f[n]);
for(int i = 0;i < m;i ++)
{
int a,b;LL c;cin >> a >> b >> c;
add(a,b,c);
add(b,a,c);
}
if(!check(INF)) puts("AFK");
else
{
while(l < r)
{
LL mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
cout << r << endl;
}
return 0;
}
by 阴语飞 @ 2022-11-07 14:24:15
每次check dist数组都需要重新赋最大值吧
by DGME @ 2022-11-07 15:50:19
太感谢了QWQ.然后st也忘记重新赋值了