#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace std;
using namespace __gnu_pbds;
int INF = 1LL<<61;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
//freopen("input.txt", "r", stdin);
// for writing output to output.txt
// freopen("output.txt", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif //fast IO
int n,m; cin >> n >> m;
int S,T,L,K; cin >> S >> T >> L >> K; S--; T--;
vector<vector<pair<int,int>>> adjlist(n);
for (int i=0; i<m; i++) {
int u,v,w; cin >> u >> v >> w; u--; v--;
adjlist[u].push_back({v,w}); adjlist[v].push_back({u,w});
}
vector<int> distS(n,INF);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> vals;
distS[S] = 0;
for (int i=0; i<n; i++) {
vals.push({distS[i],i});
}
while (vals.size()) {
pair<int,int> fir = vals.top(); vals.pop();
int u = fir.second; int dis = fir.first;
if (dis>distS[u]) continue;
for (pair<int,int> j:adjlist[u]) {
if (dis+j.second<distS[j.first]) {
vals.push({dis+j.second,j.first});
distS[j.first] = dis+j.second;
}
}
}
vector<int> distT(n,INF);
distT[T] = 0;
for (int i=0; i<n; i++) {
vals.push({distT[i],i});
}
while (vals.size()) {
pair<int,int> fir = vals.top(); vals.pop();
int u = fir.second; int dis = fir.first;
if (dis>distT[u]) continue;
for (pair<int,int> j:adjlist[u]) {
if (dis+j.second<distT[j.first]) {
vals.push({dis+j.second,j.first});
distT[j.first] = dis+j.second;
}
}
}
if (distS[T]<=K) {
cout << n*(n-1)/2 << endl;
return 0;
}
vector<int> s_sorted;
for (int i=0; i<n; i++) {
s_sorted.push_back(i);
}
sort(s_sorted.begin(), s_sorted.end(), [&](const int i1, const int i2) {
return distS[i1]>distS[i2];
}); //descending order to ensure distS[v]>distS[u]
ordered_set distv;
int su = 0;
for (int i=0; i<n; i++) {
int u = s_sorted[i];
int max_poss_weight = K-L-distS[u];
su+=distv.order_of_key({max_poss_weight+1,-INF});
distv.insert({distT[u],i});
}
cout << su << endl;
for (int i=0; i<n; i++) {
//cout << i <<" " << distS[i] << " " << distT[i] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
163 ms |
36976 KB |
Output is correct |
8 |
Correct |
177 ms |
36768 KB |
Output is correct |
9 |
Correct |
94 ms |
26036 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
856 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
203 ms |
32824 KB |
Output is correct |
15 |
Correct |
266 ms |
39364 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
860 KB |
Output is correct |
18 |
Correct |
194 ms |
38368 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
188 ms |
33080 KB |
Output is correct |
24 |
Correct |
248 ms |
39236 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
104 ms |
29168 KB |
Output is correct |
28 |
Correct |
129 ms |
24628 KB |
Output is correct |
29 |
Correct |
139 ms |
30008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
452 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
452 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
1112 KB |
Output is correct |
34 |
Correct |
1 ms |
724 KB |
Output is correct |
35 |
Correct |
2 ms |
724 KB |
Output is correct |
36 |
Correct |
3 ms |
860 KB |
Output is correct |
37 |
Correct |
2 ms |
900 KB |
Output is correct |
38 |
Correct |
2 ms |
856 KB |
Output is correct |
39 |
Correct |
2 ms |
1112 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
2 ms |
860 KB |
Output is correct |
43 |
Correct |
3 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1032 KB |
Output is correct |
45 |
Correct |
3 ms |
860 KB |
Output is correct |
46 |
Correct |
3 ms |
856 KB |
Output is correct |
47 |
Correct |
3 ms |
860 KB |
Output is correct |
48 |
Correct |
2 ms |
800 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
856 KB |
Output is correct |
51 |
Correct |
3 ms |
860 KB |
Output is correct |
52 |
Correct |
3 ms |
860 KB |
Output is correct |
53 |
Correct |
3 ms |
860 KB |
Output is correct |
54 |
Correct |
3 ms |
860 KB |
Output is correct |
55 |
Correct |
2 ms |
640 KB |
Output is correct |
56 |
Correct |
2 ms |
604 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
163 ms |
36976 KB |
Output is correct |
8 |
Correct |
177 ms |
36768 KB |
Output is correct |
9 |
Correct |
94 ms |
26036 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
856 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
203 ms |
32824 KB |
Output is correct |
15 |
Correct |
266 ms |
39364 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
860 KB |
Output is correct |
18 |
Correct |
194 ms |
38368 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
188 ms |
33080 KB |
Output is correct |
24 |
Correct |
248 ms |
39236 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
104 ms |
29168 KB |
Output is correct |
28 |
Correct |
129 ms |
24628 KB |
Output is correct |
29 |
Correct |
139 ms |
30008 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
456 KB |
Output is correct |
52 |
Correct |
0 ms |
344 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
452 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
2 ms |
1112 KB |
Output is correct |
63 |
Correct |
1 ms |
724 KB |
Output is correct |
64 |
Correct |
2 ms |
724 KB |
Output is correct |
65 |
Correct |
3 ms |
860 KB |
Output is correct |
66 |
Correct |
2 ms |
900 KB |
Output is correct |
67 |
Correct |
2 ms |
856 KB |
Output is correct |
68 |
Correct |
2 ms |
1112 KB |
Output is correct |
69 |
Correct |
2 ms |
860 KB |
Output is correct |
70 |
Correct |
1 ms |
604 KB |
Output is correct |
71 |
Correct |
2 ms |
860 KB |
Output is correct |
72 |
Correct |
3 ms |
860 KB |
Output is correct |
73 |
Correct |
3 ms |
1032 KB |
Output is correct |
74 |
Correct |
3 ms |
860 KB |
Output is correct |
75 |
Correct |
3 ms |
856 KB |
Output is correct |
76 |
Correct |
3 ms |
860 KB |
Output is correct |
77 |
Correct |
2 ms |
800 KB |
Output is correct |
78 |
Correct |
1 ms |
604 KB |
Output is correct |
79 |
Correct |
2 ms |
856 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
3 ms |
860 KB |
Output is correct |
82 |
Correct |
3 ms |
860 KB |
Output is correct |
83 |
Correct |
3 ms |
860 KB |
Output is correct |
84 |
Correct |
2 ms |
640 KB |
Output is correct |
85 |
Correct |
2 ms |
604 KB |
Output is correct |
86 |
Correct |
2 ms |
860 KB |
Output is correct |
87 |
Correct |
2 ms |
860 KB |
Output is correct |
88 |
Correct |
123 ms |
27124 KB |
Output is correct |
89 |
Correct |
145 ms |
27864 KB |
Output is correct |
90 |
Correct |
219 ms |
40700 KB |
Output is correct |
91 |
Correct |
36 ms |
14164 KB |
Output is correct |
92 |
Correct |
37 ms |
14420 KB |
Output is correct |
93 |
Correct |
186 ms |
32960 KB |
Output is correct |
94 |
Correct |
189 ms |
33924 KB |
Output is correct |
95 |
Correct |
281 ms |
40636 KB |
Output is correct |
96 |
Correct |
156 ms |
27340 KB |
Output is correct |
97 |
Correct |
279 ms |
40124 KB |
Output is correct |
98 |
Correct |
253 ms |
40160 KB |
Output is correct |
99 |
Correct |
259 ms |
39360 KB |
Output is correct |
100 |
Correct |
244 ms |
39356 KB |
Output is correct |
101 |
Correct |
38 ms |
14164 KB |
Output is correct |
102 |
Correct |
38 ms |
14420 KB |
Output is correct |
103 |
Correct |
195 ms |
32952 KB |
Output is correct |
104 |
Correct |
187 ms |
33320 KB |
Output is correct |
105 |
Correct |
278 ms |
40636 KB |
Output is correct |
106 |
Correct |
288 ms |
40896 KB |
Output is correct |
107 |
Correct |
286 ms |
42620 KB |
Output is correct |
108 |
Correct |
319 ms |
44068 KB |
Output is correct |
109 |
Correct |
127 ms |
26564 KB |
Output is correct |
110 |
Correct |
127 ms |
25968 KB |
Output is correct |
111 |
Correct |
174 ms |
30040 KB |
Output is correct |
112 |
Correct |
151 ms |
28868 KB |
Output is correct |