二分+priority_queue优化搜索。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int n=1e6;
int a,b,c,d,e,r,k[n],l,w,g[n];
vector<pair<int,int>>t[n];
int check(int x)
{
for(int i=1;i<=a;i++)
{
g[i]=-1;
}
priority_queue<pair<int,int>,vector<pair<int,int>>,less<pair<int,int>>>q;
q.push({c,e-k[c]});
g[c]=e-k[c];
while(!q.empty())
{
auto [x1,y]=q.top();
q.pop();
for(auto v:t[x1])
{
if(v.second<=x&&g[v.first]<y-k[v.first])
{
g[v.first]=y-k[v.first];
q.push({v.first,g[v.first]});
}
}
}
if(g[d]>=0)
{
return 1;
}
else
return 0;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>a>>b>>c>>d>>e;
for(int i=1;i<=a;i++)
{
cin>>k[i];
}
for(int i=1;i<=b;i++)
{
cin>>l>>r>>w;
t[l].push_back({r,w});
}
int l1=1,r1=1e9,an;
while(r1>=l1)
{
int mid=(l1+r1)/2;
//cout<<l1<<" "<<r1<<endl;
if(check(mid))
{
r1=mid-1;
an=mid;
}
else
{
l1=mid+1;
}
}
cout<<an<<endl;
}