SpookyReaper @ 2023-11-09 20:24:20
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
const int M=5e4+10;
const int MAXN=(1<<30)+(1<<29);
#define pii pair<int,int>
#define se second
priority_queue<pii,vector<pii>,greater<pii> > q;
int n,m,hp,tot,a,b,c;
int fle[N],head[N];
struct Edge
{
int next,to,cost,sumcos;
bool judge;
} edge[M<<1];
void add_edge(int qi,int zh,int val)
{
edge[++tot].cost=val;
edge[tot].to=zh;
edge[tot].next=head[qi];
head[qi]=tot;
}
bool work(int x)
{
if(x<fle[1]) return 0;
for(int i=1;i<=n;i++) edge[i].sumcos=1e9;
for(int i=1;i<=tot;i++) edge[i].judge=false;
edge[1].sumcos=1;
q.push(make_pair(0,1));
while(!q.empty())
{
int nm=q.top().se;
q.pop();
if(edge[nm].judge) continue;
edge[nm].judge=1;
for(int i=head[nm];~i;i=edge[i].next)
if(fle[edge[i].to]<=x&&!edge[i].judge&&edge[nm].sumcos+edge[i].cost<edge[edge[i].to].sumcos)
{
edge[edge[i].to].sumcos=edge[nm].sumcos+edge[i].cost;
q.push(make_pair(edge[edge[i].to].sumcos,edge[i].to));
}
}
if(edge[n].sumcos<=hp) return 1;
else return 0;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
memset(head,-1,sizeof(head));
cin>>n>>m>>hp;
for(int i=1;i<=n;i++) cin>>fle[i];
for(int i=1;i<=m;i++)
{
cin>>a>>b>>c;
add_edge(a,b,c);
add_edge(b,a,c);
}
if(work(MAXN)==0) {cout<<"AFK"; return 0;}
int left=1,right=MAXN,mid=(left+right)>>1;
while(left<=right)
{
int cs=work(mid);
if(cs) {right=mid-1; mid=(left+right)>>1;}
else {left=mid+1; mid=(left+right)>>1;}
}
cout<<left;
return 0;
}
码风可能有些奇怪,请见谅
by SpookyReaper @ 2023-11-09 20:25:24
hack的情况是全WA
by Love_Natsu @ 2024-01-20 21:39:23
同样的问题,蹲一下。。。