#pragma GCC optimize("Ofast") #include #include using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,s,t,k; cin >> n >> s >> t >> k; s--; t--; vector x(n); for(int i=0;i> x[i]; } vector>> g(n); int m; cin >> m; for(int i=0;i> a >> b >> y; a--; b--; g[a].push_back({b,y}); } const ll INF=1e18; vector> d(n,vector(k,INF)); vector>> rev(n,vector>(k,{-1,-1})); d[s][0]=x[s]; priority_queue>,vector>>,greater>>> pq; pq.push({d[s][0],{s,0}}); while(pq.size()){ auto p=pq.top(); pq.pop(); int ss=p.second.first,cn=p.second.second; if(p.first!=d[ss][cn])continue; for(auto to:g[ss]){ ll cost=p.first+to.second+x[to.first]; int nxt=to.first; int nxc=min(k-1,cn+1); if(cost v={t}; while(p.second>=0){ int nxt=p.first,nxc=p.second; v.push_back(nxt); p=rev[nxt][nxc]; } reverse(v.begin(), v.end()); printf("%d\n",v.size()); for(int i=0;i