二分+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 ma