#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<18;
bool vis[N];
ll dis[2][N];
pair<ll, int> ds[N], dt[N];
vector<pair<int, ll>> ed[N];
void Dijkstra(int r, int s, int n)
{
int v;
priority_queue<pair<ll, int>> q;
for(int i = 1; i <= n; ++i)
{dis[r][i] = I; vis[i] = false;}
dis[r][s] = 0LL;
q.push(make_pair(0, s));
while((int)q.size() > 0)
{
v = q.top().nd; q.pop();
if(vis[v]) continue;
vis[v] = true;
for(int i = 0; i < (int)ed[v].size(); ++i)
{
ll o = dis[r][v] + ed[v][i].nd;
if(o < dis[r][ed[v][i].st])
{
dis[r][ed[v][i].st] = o;
q.push(make_pair(-o, ed[v][i].st));
}
}
}
}
void Solve()
{
int n, m, a, b, s, t, l, c;
ll k;
ll ans = 0LL;
cin >> n >> m;
cin >> s >> t >> l >> k;
for(int i = 1; i <= m; ++i)
{
cin >> a >> b >> c;
ed[a].pb(make_pair(b, c));
ed[b].pb(make_pair(a, c));
}
Dijkstra(0, s, n);
Dijkstra(1, t, n);
if(dis[0][t] <= k)
{
cout << ((ll)n * (ll)(n - 1)) / 2LL << "\n";
return;
}
for(int i = 1; i <= n; ++i)
{
ds[i] = make_pair(dis[0][i], i);
dt[i] = make_pair(dis[1][i], i);
}
sort(ds + 1, ds + 1 + n);
sort(dt + 1, dt + 1 + n);
int j = n;
for(int i = 1; i <= n; ++i)
{
while(j > 0 && ds[i].st + dt[j].st + (ll)l > k)
--j;
ans += (ll)j;
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//int t; cin >> t;
//while(t--)
Solve();
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... |