hengzm @ 2024-01-31 15:47:35
只得了80分wa了#5#8#11,12,13 求求大佬解惑
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, int> PII;
const int N = 1e4+10;
const int M = 1e5+10;
const LL inf = LLONG_MAX/3;
int e[M], ne[M], h[N], idx;
LL w[M], dist[M];
bool vis[N];
int n, m, hp;
LL ans = inf;
struct node{
LL f;
int id;
}node[N];
void add(int a, int b, LL c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dijkstra()
{
priority_queue<PII, vector<PII>, greater<PII>> q;
dist[1] = 0;
q.push({0, 1});
while(q.size())
{
PII t = q.top();
q.pop();
int ver = t.second;
if(vis[ver]) continue;
vis[ver] = 1;
for (int i = h[ver]; i != -1; i = ne[i])
{
int j = e[i];
if(dist[j] > dist[ver] + w[i])
{
dist[j] = dist[ver] + w[i];
q.push({dist[j], j});
}
}
}
}
bool check(int x)
{
// memset(vis, 0, sizeof vis);
// memset(dist, 0x3f, sizeof dist);
for (int i = 1; i <= n; i++)
{
dist[i] = inf;
if(i > x) {
vis[i] = 1;
if(node[i].id == 1 || node[i].id == n)
return false;
}
else vis[i] = 0;
}
dijkstra();
if(dist[n] > hp) return false;
else{
return true;
}
}
bool cmp(struct node x, struct node y)
{
return x.f < y.f;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n>>m>>hp;
memset(h, -1, sizeof h);
for (int i = 1; i <= n; i++) {
cin>>node[i].f;
node[i].id = i;
}
sort(node, node + n, cmp);//边权从小到大排序
while(m--)
{
int a, b, c;
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
int l = 1, r = n + 1;
while(l < r)
{
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
if(check(l)) cout<<node[l].f;
else cout<<"AFK";
return 0;
}