#include <bits/stdc++.h>
#define pi pair<int, int>
#define int long long
#define ff first
#define ss second
using namespace std;
const long long N = 3000 + 5;
vector<pi> graph[N];
vector<int> dijkstra(int start)
{
vector<int> dist(N, 1e18);
priority_queue<pi, vector<pi>, greater<pi>> q;
q.push({0, start});
dist[start] = 0;
int node, weight;
while (q.size())
{
node = q.top().ss;
q.pop();
for (auto i : graph[node])
{
if (dist[i.ss] > dist[node] + i.ff)
{
dist[i.ss] = dist[node] + i.ff;
q.push({dist[i.ss], i.ss});
}
}
}
return dist;
}
void solve()
{
int n, m;
cin >> n >> m;
int s, t, l, k;
cin >> s >> t >> l >> k;
int u, v, w;
for (int i = 0; i < m; i++)
{
cin >> u >> v >> w;
graph[u].push_back({w, v});
graph[v].push_back({w, u});
}
vector<int> sdist = dijkstra(s);
vector<int> tdist = dijkstra(t);
if (sdist[t] <= k)
{
cout << n * (n - 1) / 2;
return;
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (sdist[i] + tdist[j] + l <= k)
{
ans++;
}
else if (sdist[j] + tdist[i] + l <= k)
{
ans++;
}
}
}
cout << ans << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
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... |