This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;
const int N=2e5+5, mod = 1e9+7, inf = 1e18;
int n, m, s, t, l, k;
int ds[N], dt[N];
vector<ii> adj[N];
priority_queue<ii,vector<ii>,greater<ii>> pq;
signed main() {
//freopen("tmp.inp", "r", stdin);
//freopen("tmp.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> s >> t >> l >> k;
for(int i=1; i<=m; i++) {
int a, b, c; cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
for (int i=1; i<=n; i++) ds[i] = inf;
ds[s] = 0; pq.push({0, s});
while(!pq.empty()) {
int u = pq.top().se, d = pq.top().fi; pq.pop();
if(d>ds[u]) continue;
for (auto [v, w]: adj[u]) {
if(ds[v]>ds[u]+w) {
ds[v] = ds[u]+w;
pq.push({ds[v], v});
}
}
}
for (int i=1; i<=n; i++) dt[i] = inf;
dt[t] = 0; pq.push({0, t});
while(!pq.empty()) {
int u = pq.top().se, d = pq.top().fi; pq.pop();
if(d>dt[u]) continue;
for (auto [v, w]: adj[u]) {
if(dt[v]>dt[u]+w) {
dt[v] = dt[u]+w;
pq.push({dt[v], v});
}
}
}
for(int i=1; i<=n; i++) {
if(ds[i]+dt[i]<=k) {
cout << n*(n-1)/2;
return 0;
}
}
int ans = 0;
sort(ds+1, ds+n+1); sort(dt+1, dt+n+1);
for(int i=1; i<=n; i++) {
int pos = upper_bound(dt+1, dt+n+1, k-l-ds[i])-dt-1;
ans += pos;
}
cout << ans;
}
# | 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... |