考场思路。
考虑从猫洞跑一遍 dijkstra 处理出每一个点到猫洞的距离。
然后考虑从鼠洞向外进行广搜,同时维护一个最小值,表示路径上所有从鼠洞出发到这里的时间减去猫洞到这里的时间,如果这个值比零小就不可行了,打标记需要记录到这个点时,刚刚说的那个值的最大值。
代码等我写完。
Ac code
//Author:Kevin Z K Y
#include <bits/stdc++.h>
#define up(a,b,c) for(int (a)=(b);(a)<=(c);(a)++)
#define dn(a,b,c) for(int (a)=(b);(a)>=(c);(a)--)
#define fst first
#define sed second
#define Max(x,y) (((x)>(y))?(x):(y))
#define Min(x,y) (((x)<(y))?(x):(y))
#define Abs(x) (((x)<0)?(-(x)):(x))
using namespace std;
using us = unsigned short ;using ldb = long double ;
using ull = unsigned long long ;using ui = unsigned int ;
using ll = long long ;using hint = __int128 ;
using pii = pair<int,int> ;using pll = pair<ll,ll> ;
using pil = pair<int,ll> ;using vpil = vector<pil> ;
using pli = pair<ll,int> ;using vpli = vector<pli> ;
using vi = vector<int> ;using vl = vector<ll> ;
using vpi = vector<pii> ;using vpl = vector<pll> ;
using db = double ;namespace mystl{
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++
char buf[1<<20], *p1=buf, *p2=buf, sr[1<<23], z[23], nc;int C=-1 ,Z=0;
template <typename T> inline void read ( T & x ) { bool flag = false ;
while( nc = gc() ,(nc<48||nc>57) && nc!=-1)flag|=(nc==45);x=nc-48;
while(nc=gc(),47<nc&&nc<58)x=(x<<3)+(x<<1)+(nc^48); if(flag)x=-x;}
template < typename T , typename ... Args_Arrays_Typename_KevinZ99 >
void read(T&x,Args_Arrays_Typename_KevinZ99&...a){read(x);read(a...);}
inline void ot( ) { fwrite( sr , 1 , C + 1, stdout ) ; C = - 1 ; }
inline void flush( ) { if ( C > 1<<22 ) ot() ; } template <typename T>
inline void write(T x,char t){ int y = 0 ; if ( x < 0 ) y = 1, x = -x;
while( z [ ++ Z ] = x % 10 + 48 , x /= 10) ; if( y ) z[ ++Z ]='-';
while( sr[ ++ C ] = z[ Z ] , -- Z ) ; sr [ ++C ] = t ; flush() ; }
}using namespace mystl;
namespace my{
constexpr int N=(int)(1e5+5),P=(int)(998244353);
constexpr ll inf=(ll)(1e18);
int n,m,a,b;
vpil g[N];
bool vis[N];
ll dist[N],mx[N],c[N];
inline void dijkstra(){
priority_queue<pli,vector<pli>,greater<pli>>q;
up(i,1,n)dist[i]=inf,vis[i]=false;
q.push({dist[b]=0,b});
while(!q.empty()){
int k=q.top().sed;q.pop();
if(vis[k])continue;
vis[k]=true;
for(pil v:g[k])if(dist[k]+v.sed<dist[v.fst])
dist[v.fst]=dist[k]+v.sed,q.push({dist[v.fst],v.fst});
}
}
inline void SOLVE(){
read(n,m,b,a);
up(i,1,n)read(c[i]);
up(i,1,m){
int x,y;ll w;
read(x,y,w);
g[x].push_back({y,w});
g[y].push_back({x,w});
}
dijkstra();
queue<pil>q;
mx[a]=dist[a];
q.push({a,dist[a]});
ll ans=0;
while(!q.empty()){
pil k=q.front();q.pop();
for(pil v:g[k.fst]){
ll mn=Min(k.sed-v.sed,dist[v.fst]);
if(mn>mx[v.fst])mx[v.fst]=mn,q.push({v.fst,mn});
}
}
up(i,1,n)if(mx[i]>0)ans+=c[i];
cout<<ans<<'\n';
}
}
int main(){
// freopen("","r",stdin);
// freopen("","w",stdout);
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int _=1;while(_--)my::SOLVE();return 0;
}