#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 2e5 + 15;
int n, m, S, T;
ll L, limit;
vector<pair<int,int>> g[N];
vector<ll> distS, distT;
void dijk(vector<ll>& dist, int root){
dist.resize(N, 0x3f);
dist[root] = 0;
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.push({0,root});
while(!pq.empty()){
ll wu; int u; tie(wu, u) = pq.top(); pq.pop();
if(wu > dist[u]) continue;
for(auto [v, wv] : g[u]){
if(dist[v] > dist[u] + wv){
dist[v] = dist[u] + wv;
pq.push({dist[v],v});
}
}
}
}
void solve(){
cin >> n >> m;
cin >> S >> T >> L >> limit;
for(int i = 1; i <= m; i++){
int u, v, w; cin >> u >> v >> w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
dijk(distS, S);
dijk(distT, T);
if(distS[T] <= limit){//match whatever
cout << 1LL*n*(n-1) / 2;
return;
}
ll ans = 0;
vector<ll> A, B;
//a + b + L <= limit
//a <= limit - L - b
//sort a decrease, sort b increase -> greed
for(int i = 1; i <= n; i++){
A.push_back(distS[i]);
B.push_back(distT[i]);
}
sort(all(A), greater<ll>()); sort(all(B));
for(int i = 0,j = 0; i < A.size(); i++){
while(j < B.size() && B[j] <= limit - L - A[i]) j++;
ans += j;
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "task"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
Compilation message
Main.cpp: In function 'void dijk(std::vector<long long int>&, int)':
Main.cpp:25:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | for(auto [v, wv] : g[u]){
| ^
Main.cpp: In function 'void solve()':
Main.cpp:68:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i = 0,j = 0; i < A.size(); i++){
| ~~^~~~~~~~~~
Main.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | while(j < B.size() && B[j] <= limit - L - A[i]) j++;
| ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8072 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Correct |
3 ms |
8272 KB |
Output is correct |
5 |
Correct |
4 ms |
8272 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
58 ms |
19536 KB |
Output is correct |
8 |
Correct |
74 ms |
21064 KB |
Output is correct |
9 |
Correct |
64 ms |
18316 KB |
Output is correct |
10 |
Correct |
4 ms |
8272 KB |
Output is correct |
11 |
Correct |
4 ms |
8272 KB |
Output is correct |
12 |
Correct |
4 ms |
8284 KB |
Output is correct |
13 |
Correct |
5 ms |
8272 KB |
Output is correct |
14 |
Correct |
41 ms |
18764 KB |
Output is correct |
15 |
Correct |
143 ms |
20536 KB |
Output is correct |
16 |
Correct |
4 ms |
8272 KB |
Output is correct |
17 |
Correct |
5 ms |
8272 KB |
Output is correct |
18 |
Correct |
71 ms |
21600 KB |
Output is correct |
19 |
Correct |
4 ms |
8440 KB |
Output is correct |
20 |
Correct |
3 ms |
8272 KB |
Output is correct |
21 |
Correct |
5 ms |
8272 KB |
Output is correct |
22 |
Correct |
5 ms |
8500 KB |
Output is correct |
23 |
Correct |
42 ms |
18876 KB |
Output is correct |
24 |
Correct |
143 ms |
20396 KB |
Output is correct |
25 |
Correct |
4 ms |
8272 KB |
Output is correct |
26 |
Correct |
5 ms |
8528 KB |
Output is correct |
27 |
Correct |
89 ms |
24116 KB |
Output is correct |
28 |
Correct |
66 ms |
18124 KB |
Output is correct |
29 |
Correct |
55 ms |
18792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
6 ms |
8272 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Incorrect |
5 ms |
8272 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
6 ms |
8272 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Incorrect |
5 ms |
8272 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8072 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Correct |
3 ms |
8272 KB |
Output is correct |
5 |
Correct |
4 ms |
8272 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
58 ms |
19536 KB |
Output is correct |
8 |
Correct |
74 ms |
21064 KB |
Output is correct |
9 |
Correct |
64 ms |
18316 KB |
Output is correct |
10 |
Correct |
4 ms |
8272 KB |
Output is correct |
11 |
Correct |
4 ms |
8272 KB |
Output is correct |
12 |
Correct |
4 ms |
8284 KB |
Output is correct |
13 |
Correct |
5 ms |
8272 KB |
Output is correct |
14 |
Correct |
41 ms |
18764 KB |
Output is correct |
15 |
Correct |
143 ms |
20536 KB |
Output is correct |
16 |
Correct |
4 ms |
8272 KB |
Output is correct |
17 |
Correct |
5 ms |
8272 KB |
Output is correct |
18 |
Correct |
71 ms |
21600 KB |
Output is correct |
19 |
Correct |
4 ms |
8440 KB |
Output is correct |
20 |
Correct |
3 ms |
8272 KB |
Output is correct |
21 |
Correct |
5 ms |
8272 KB |
Output is correct |
22 |
Correct |
5 ms |
8500 KB |
Output is correct |
23 |
Correct |
42 ms |
18876 KB |
Output is correct |
24 |
Correct |
143 ms |
20396 KB |
Output is correct |
25 |
Correct |
4 ms |
8272 KB |
Output is correct |
26 |
Correct |
5 ms |
8528 KB |
Output is correct |
27 |
Correct |
89 ms |
24116 KB |
Output is correct |
28 |
Correct |
66 ms |
18124 KB |
Output is correct |
29 |
Correct |
55 ms |
18792 KB |
Output is correct |
30 |
Correct |
4 ms |
8272 KB |
Output is correct |
31 |
Correct |
6 ms |
8272 KB |
Output is correct |
32 |
Correct |
4 ms |
8272 KB |
Output is correct |
33 |
Incorrect |
5 ms |
8272 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |