Asunataisiki @ 2021-09-24 22:17:10
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e5+5;
int e[N], ne[N], h[N], w[N] ,idx;
//链式前向星
int n, m, hp;
int f[N], dis[N], vis[N];
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
bool distra(int money)
{
memset(vis, 0, sizeof vis);
memset(dis, 0x3f, sizeof dis);
dis[1] = 0;
priority_queue<PII, vector<PII>, greater<PII> > q;
q.push({0, 1});
while(!q.empty()){
PII no = q.top(); q.pop();
int distance = no.first;
int u = no.second;
if(vis[u]) continue;
vis[u] = 1;
for(int i = h[u]; i != -1; i = ne[i]){
int j = e[i];
if(dis[j] > distance + w[i] && f[j] <= money){
dis[j] = distance + w[i];
q.push({dis[j], j});
}
}
}
if(dis[n] <= hp) return true;
else return false;
}
int main()
{
memset(h, -1, sizeof h);
cin >> n >> m >> hp;
int l = 0x3f3f3f3f, r = 0;
for(int i = 1; i <= n; i++){
cin >> f[i];
l = min(l, f[i]);
r = max(r, f[i]);
}
for(int i = 1; i <= m; i++){
int a, b, c;
cin >> a >> b >> c;
add(a, b, c);
add(b, a, c);
}
int flag = 0;
while(l < r){
int mid = (l + r) >> 1;
if(distra(mid)){
flag = 1;
r = mid;
}
else l = mid + 1;
}
if(!flag) cout << "AFK" << endl;
else cout << l << endl;
return 0;
}
by 风中の菜鸡 @ 2021-09-24 22:22:36
数据太水?
by HYdroKomide @ 2021-09-24 22:30:58
样例出锅?
by HYdroKomide @ 2021-09-24 22:31:39
刚做一道这种情况的题,真的太迷惑人了。
by 居sz_zje然 @ 2022-03-08 10:05:29
离大谱嗷
by Archmushroom @ 2022-09-06 16:28:49
样例,就是最好的hack!