#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define int long long
using namespace std;
typedef long long ll;
const int N = 2e5 + 15;
const ll INF = 1e18;
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, INF);
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)); sort(all(B), greater<ll>());
for(int i = 0,j = 0; i < B.size(); i++){
while(j < A.size() && A[j] <= limit - L - B[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>&, long long int)':
Main.cpp:27:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [v, wv] : g[u]){
| ^
Main.cpp: In function 'void solve()':
Main.cpp:70:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0,j = 0; i < B.size(); i++){
| ~~^~~~~~~~~~
Main.cpp:71:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | while(j < A.size() && A[j] <= limit - L - B[i]) j++;
| ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
4 ms |
8272 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Correct |
4 ms |
8272 KB |
Output is correct |
5 |
Correct |
5 ms |
8552 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
59 ms |
22852 KB |
Output is correct |
8 |
Correct |
78 ms |
22352 KB |
Output is correct |
9 |
Correct |
68 ms |
21340 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Correct |
4 ms |
8272 KB |
Output is correct |
12 |
Correct |
5 ms |
8336 KB |
Output is correct |
13 |
Correct |
5 ms |
8528 KB |
Output is correct |
14 |
Correct |
45 ms |
18792 KB |
Output is correct |
15 |
Correct |
149 ms |
23980 KB |
Output is correct |
16 |
Correct |
4 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
77 ms |
22800 KB |
Output is correct |
19 |
Correct |
4 ms |
8304 KB |
Output is correct |
20 |
Correct |
4 ms |
8272 KB |
Output is correct |
21 |
Correct |
5 ms |
8272 KB |
Output is correct |
22 |
Correct |
6 ms |
8528 KB |
Output is correct |
23 |
Correct |
45 ms |
18804 KB |
Output is correct |
24 |
Correct |
139 ms |
23980 KB |
Output is correct |
25 |
Correct |
4 ms |
8272 KB |
Output is correct |
26 |
Correct |
5 ms |
8528 KB |
Output is correct |
27 |
Correct |
81 ms |
25656 KB |
Output is correct |
28 |
Correct |
79 ms |
20508 KB |
Output is correct |
29 |
Correct |
65 ms |
21936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8272 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Correct |
4 ms |
8272 KB |
Output is correct |
5 |
Correct |
4 ms |
8444 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
3 ms |
8272 KB |
Output is correct |
8 |
Correct |
4 ms |
8272 KB |
Output is correct |
9 |
Correct |
4 ms |
8292 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Correct |
3 ms |
8272 KB |
Output is correct |
12 |
Correct |
4 ms |
8272 KB |
Output is correct |
13 |
Correct |
4 ms |
8272 KB |
Output is correct |
14 |
Correct |
4 ms |
8272 KB |
Output is correct |
15 |
Correct |
3 ms |
8272 KB |
Output is correct |
16 |
Correct |
4 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
4 ms |
8272 KB |
Output is correct |
19 |
Correct |
4 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
8272 KB |
Output is correct |
21 |
Correct |
4 ms |
8272 KB |
Output is correct |
22 |
Correct |
4 ms |
8272 KB |
Output is correct |
23 |
Correct |
3 ms |
8236 KB |
Output is correct |
24 |
Correct |
4 ms |
8496 KB |
Output is correct |
25 |
Correct |
4 ms |
8272 KB |
Output is correct |
26 |
Correct |
4 ms |
8272 KB |
Output is correct |
27 |
Correct |
3 ms |
8272 KB |
Output is correct |
28 |
Correct |
4 ms |
8252 KB |
Output is correct |
29 |
Correct |
4 ms |
8272 KB |
Output is correct |
30 |
Correct |
4 ms |
8272 KB |
Output is correct |
31 |
Correct |
3 ms |
8272 KB |
Output is correct |
32 |
Correct |
3 ms |
8272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
3 ms |
8272 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Correct |
4 ms |
8272 KB |
Output is correct |
5 |
Correct |
4 ms |
8444 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
3 ms |
8272 KB |
Output is correct |
8 |
Correct |
4 ms |
8272 KB |
Output is correct |
9 |
Correct |
4 ms |
8292 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Correct |
3 ms |
8272 KB |
Output is correct |
12 |
Correct |
4 ms |
8272 KB |
Output is correct |
13 |
Correct |
4 ms |
8272 KB |
Output is correct |
14 |
Correct |
4 ms |
8272 KB |
Output is correct |
15 |
Correct |
3 ms |
8272 KB |
Output is correct |
16 |
Correct |
4 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
4 ms |
8272 KB |
Output is correct |
19 |
Correct |
4 ms |
8284 KB |
Output is correct |
20 |
Correct |
4 ms |
8272 KB |
Output is correct |
21 |
Correct |
4 ms |
8272 KB |
Output is correct |
22 |
Correct |
4 ms |
8272 KB |
Output is correct |
23 |
Correct |
3 ms |
8236 KB |
Output is correct |
24 |
Correct |
4 ms |
8496 KB |
Output is correct |
25 |
Correct |
4 ms |
8272 KB |
Output is correct |
26 |
Correct |
4 ms |
8272 KB |
Output is correct |
27 |
Correct |
3 ms |
8272 KB |
Output is correct |
28 |
Correct |
4 ms |
8252 KB |
Output is correct |
29 |
Correct |
4 ms |
8272 KB |
Output is correct |
30 |
Correct |
4 ms |
8272 KB |
Output is correct |
31 |
Correct |
3 ms |
8272 KB |
Output is correct |
32 |
Correct |
3 ms |
8272 KB |
Output is correct |
33 |
Correct |
4 ms |
8528 KB |
Output is correct |
34 |
Correct |
4 ms |
8528 KB |
Output is correct |
35 |
Correct |
6 ms |
8272 KB |
Output is correct |
36 |
Correct |
5 ms |
8528 KB |
Output is correct |
37 |
Correct |
4 ms |
8272 KB |
Output is correct |
38 |
Correct |
4 ms |
8284 KB |
Output is correct |
39 |
Correct |
5 ms |
8528 KB |
Output is correct |
40 |
Correct |
5 ms |
8528 KB |
Output is correct |
41 |
Correct |
4 ms |
8344 KB |
Output is correct |
42 |
Correct |
4 ms |
8272 KB |
Output is correct |
43 |
Correct |
6 ms |
8544 KB |
Output is correct |
44 |
Correct |
5 ms |
8528 KB |
Output is correct |
45 |
Correct |
6 ms |
8528 KB |
Output is correct |
46 |
Correct |
6 ms |
8528 KB |
Output is correct |
47 |
Correct |
6 ms |
8528 KB |
Output is correct |
48 |
Correct |
5 ms |
8272 KB |
Output is correct |
49 |
Correct |
5 ms |
8272 KB |
Output is correct |
50 |
Correct |
4 ms |
8244 KB |
Output is correct |
51 |
Correct |
6 ms |
8528 KB |
Output is correct |
52 |
Correct |
5 ms |
8524 KB |
Output is correct |
53 |
Correct |
7 ms |
8528 KB |
Output is correct |
54 |
Correct |
6 ms |
8528 KB |
Output is correct |
55 |
Correct |
5 ms |
8528 KB |
Output is correct |
56 |
Correct |
5 ms |
8288 KB |
Output is correct |
57 |
Correct |
5 ms |
8272 KB |
Output is correct |
58 |
Correct |
5 ms |
8272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8272 KB |
Output is correct |
2 |
Correct |
4 ms |
8272 KB |
Output is correct |
3 |
Correct |
4 ms |
8272 KB |
Output is correct |
4 |
Correct |
4 ms |
8272 KB |
Output is correct |
5 |
Correct |
5 ms |
8552 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
59 ms |
22852 KB |
Output is correct |
8 |
Correct |
78 ms |
22352 KB |
Output is correct |
9 |
Correct |
68 ms |
21340 KB |
Output is correct |
10 |
Correct |
5 ms |
8272 KB |
Output is correct |
11 |
Correct |
4 ms |
8272 KB |
Output is correct |
12 |
Correct |
5 ms |
8336 KB |
Output is correct |
13 |
Correct |
5 ms |
8528 KB |
Output is correct |
14 |
Correct |
45 ms |
18792 KB |
Output is correct |
15 |
Correct |
149 ms |
23980 KB |
Output is correct |
16 |
Correct |
4 ms |
8272 KB |
Output is correct |
17 |
Correct |
4 ms |
8272 KB |
Output is correct |
18 |
Correct |
77 ms |
22800 KB |
Output is correct |
19 |
Correct |
4 ms |
8304 KB |
Output is correct |
20 |
Correct |
4 ms |
8272 KB |
Output is correct |
21 |
Correct |
5 ms |
8272 KB |
Output is correct |
22 |
Correct |
6 ms |
8528 KB |
Output is correct |
23 |
Correct |
45 ms |
18804 KB |
Output is correct |
24 |
Correct |
139 ms |
23980 KB |
Output is correct |
25 |
Correct |
4 ms |
8272 KB |
Output is correct |
26 |
Correct |
5 ms |
8528 KB |
Output is correct |
27 |
Correct |
81 ms |
25656 KB |
Output is correct |
28 |
Correct |
79 ms |
20508 KB |
Output is correct |
29 |
Correct |
65 ms |
21936 KB |
Output is correct |
30 |
Correct |
4 ms |
8272 KB |
Output is correct |
31 |
Correct |
3 ms |
8272 KB |
Output is correct |
32 |
Correct |
4 ms |
8272 KB |
Output is correct |
33 |
Correct |
4 ms |
8272 KB |
Output is correct |
34 |
Correct |
4 ms |
8444 KB |
Output is correct |
35 |
Correct |
4 ms |
8272 KB |
Output is correct |
36 |
Correct |
3 ms |
8272 KB |
Output is correct |
37 |
Correct |
4 ms |
8272 KB |
Output is correct |
38 |
Correct |
4 ms |
8292 KB |
Output is correct |
39 |
Correct |
5 ms |
8272 KB |
Output is correct |
40 |
Correct |
3 ms |
8272 KB |
Output is correct |
41 |
Correct |
4 ms |
8272 KB |
Output is correct |
42 |
Correct |
4 ms |
8272 KB |
Output is correct |
43 |
Correct |
4 ms |
8272 KB |
Output is correct |
44 |
Correct |
3 ms |
8272 KB |
Output is correct |
45 |
Correct |
4 ms |
8272 KB |
Output is correct |
46 |
Correct |
4 ms |
8272 KB |
Output is correct |
47 |
Correct |
4 ms |
8272 KB |
Output is correct |
48 |
Correct |
4 ms |
8284 KB |
Output is correct |
49 |
Correct |
4 ms |
8272 KB |
Output is correct |
50 |
Correct |
4 ms |
8272 KB |
Output is correct |
51 |
Correct |
4 ms |
8272 KB |
Output is correct |
52 |
Correct |
3 ms |
8236 KB |
Output is correct |
53 |
Correct |
4 ms |
8496 KB |
Output is correct |
54 |
Correct |
4 ms |
8272 KB |
Output is correct |
55 |
Correct |
4 ms |
8272 KB |
Output is correct |
56 |
Correct |
3 ms |
8272 KB |
Output is correct |
57 |
Correct |
4 ms |
8252 KB |
Output is correct |
58 |
Correct |
4 ms |
8272 KB |
Output is correct |
59 |
Correct |
4 ms |
8272 KB |
Output is correct |
60 |
Correct |
3 ms |
8272 KB |
Output is correct |
61 |
Correct |
3 ms |
8272 KB |
Output is correct |
62 |
Correct |
4 ms |
8528 KB |
Output is correct |
63 |
Correct |
4 ms |
8528 KB |
Output is correct |
64 |
Correct |
6 ms |
8272 KB |
Output is correct |
65 |
Correct |
5 ms |
8528 KB |
Output is correct |
66 |
Correct |
4 ms |
8272 KB |
Output is correct |
67 |
Correct |
4 ms |
8284 KB |
Output is correct |
68 |
Correct |
5 ms |
8528 KB |
Output is correct |
69 |
Correct |
5 ms |
8528 KB |
Output is correct |
70 |
Correct |
4 ms |
8344 KB |
Output is correct |
71 |
Correct |
4 ms |
8272 KB |
Output is correct |
72 |
Correct |
6 ms |
8544 KB |
Output is correct |
73 |
Correct |
5 ms |
8528 KB |
Output is correct |
74 |
Correct |
6 ms |
8528 KB |
Output is correct |
75 |
Correct |
6 ms |
8528 KB |
Output is correct |
76 |
Correct |
6 ms |
8528 KB |
Output is correct |
77 |
Correct |
5 ms |
8272 KB |
Output is correct |
78 |
Correct |
5 ms |
8272 KB |
Output is correct |
79 |
Correct |
4 ms |
8244 KB |
Output is correct |
80 |
Correct |
6 ms |
8528 KB |
Output is correct |
81 |
Correct |
5 ms |
8524 KB |
Output is correct |
82 |
Correct |
7 ms |
8528 KB |
Output is correct |
83 |
Correct |
6 ms |
8528 KB |
Output is correct |
84 |
Correct |
5 ms |
8528 KB |
Output is correct |
85 |
Correct |
5 ms |
8288 KB |
Output is correct |
86 |
Correct |
5 ms |
8272 KB |
Output is correct |
87 |
Correct |
5 ms |
8272 KB |
Output is correct |
88 |
Correct |
101 ms |
19116 KB |
Output is correct |
89 |
Correct |
120 ms |
21340 KB |
Output is correct |
90 |
Correct |
117 ms |
26900 KB |
Output is correct |
91 |
Correct |
45 ms |
18772 KB |
Output is correct |
92 |
Correct |
46 ms |
19072 KB |
Output is correct |
93 |
Correct |
47 ms |
18884 KB |
Output is correct |
94 |
Correct |
57 ms |
18784 KB |
Output is correct |
95 |
Correct |
184 ms |
24196 KB |
Output is correct |
96 |
Correct |
136 ms |
20156 KB |
Output is correct |
97 |
Correct |
156 ms |
26424 KB |
Output is correct |
98 |
Correct |
133 ms |
23984 KB |
Output is correct |
99 |
Correct |
74 ms |
22960 KB |
Output is correct |
100 |
Correct |
79 ms |
25840 KB |
Output is correct |
101 |
Correct |
49 ms |
20552 KB |
Output is correct |
102 |
Correct |
52 ms |
20816 KB |
Output is correct |
103 |
Correct |
59 ms |
19960 KB |
Output is correct |
104 |
Correct |
55 ms |
19232 KB |
Output is correct |
105 |
Correct |
188 ms |
26412 KB |
Output is correct |
106 |
Correct |
157 ms |
24872 KB |
Output is correct |
107 |
Correct |
163 ms |
26512 KB |
Output is correct |
108 |
Correct |
183 ms |
29276 KB |
Output is correct |
109 |
Correct |
82 ms |
22848 KB |
Output is correct |
110 |
Correct |
86 ms |
22764 KB |
Output is correct |
111 |
Correct |
101 ms |
24216 KB |
Output is correct |
112 |
Correct |
102 ms |
24700 KB |
Output is correct |