#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define ull unsigned long long
#define llll __int128
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "|"
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF = 1e16;
ll n, m;
vector<pll> adj[200005];
ll dist[2][200005];
bool vis[2][200005];
void dijkstra(ll idx, ll st){
priority_queue<pll, vector<pll>, greater<pll>> pq;
for (int i=0; i<=n; i++){
dist[idx][i] = INF;
vis[idx][i] = false;
}
dist[idx][st] = 0; vis[idx][st] = 0;
pq.push({0, st});
while (!pq.empty()){
ll weight = pq.top().first, cur = pq.top().second;
pq.pop();
if (dist[idx][cur] < weight) continue;
vis[idx][cur] = true;
for (auto [w, node]: adj[cur]){
if (dist[idx][node] > dist[idx][cur]+w && !vis[idx][node]){
dist[idx][node] = dist[idx][cur]+w;
pq.push({dist[idx][node], node});
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
ll s, t, l, k; cin >> s >> t >> l >> k;
for (int i=0; i<m; i++){
ll a, b, c; cin >> a >> b >> c;
adj[a].push_back({c, b});
adj[b].push_back({c, a});
}
dijkstra(0, s);
dijkstra(1, t);
sort(dist[1]+1, dist[1]+n+1);
// cout << "\n";
// for (int i=1; i<=n; i++) cout << dist[0][i] << " ";
// cout << "\n";
// for (int i=1; i<=n; i++) cout << dist[1][i] << " ";
// cout << "\n";
ll ans = 0;
for (int i=1; i<=n; i++){
ll req = k-l-dist[0][i];
ll res = upper_bound(dist[1]+1, dist[1]+n+1, req) - dist[1]; res--;
// cout << res << " ";
ans += res;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |