#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
#define int int64_t
const int MAXN = 2e5+3;
const int64_t INF = 1e18+69;
int n, m;
vector<pair<int,int>> e[MAXN];
int Start, End, lol, mintime;
int64_t ans;
int64_t f[2][MAXN];
void dijkstra(int s, int64_t f[]){
fill(f+1,f+1+n,INF);
priority_queue<pair<int64_t,int>, vector<pair<int64_t,int>>, greater<pair<int64_t,int>>> pq;
pq.emplace(0, s);
f[s] = 0;
while(!pq.empty()){
pair<int64_t,int> z = pq.top(); pq.pop();
int64_t du = z.first;
int u=z.second;
if(du>f[u])continue;
for(pair<int,int> &z : e[u]){
int v=z.first, w=z.second;
if(f[u]+w<f[v]){
f[v] = f[u]+w;
pq.emplace(f[v], v);
}
}
}
}
signed main()
{
cin.tie(0) -> sync_with_stdio(0);
if(fopen("*.inp", "r")){
freopen("*.inp", "r",stdin);
freopen("*.out", "w",stdout);
}
cin >> n >> m;
cin >> Start >> End >> lol >> mintime;
for(int u, v, w, i=0; i<m; ++i){
cin >> u >> v >> w;
e[u].emplace_back(v, w);
e[v].emplace_back(u, w);
}
dijkstra(Start, f[0]);
dijkstra(End, f[1]);
if(f[0][End]<=mintime) {cout << n*(n-1)/2; return 0;}
sort(f[0]+1, f[0]+1+n);
sort(f[1]+1, f[1]+1+n);
for(int i=1; i<=n; ++i){
if(mintime<lol+f[1][i])break;
auto x = upper_bound(f[0]+1, f[0]+1+n, mintime-lol-f[1][i]) - f[0];
ans += x-1;
}
cout << ans;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen("*.inp", "r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen("*.out", "w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5244 KB |
Output is correct |
7 |
Correct |
55 ms |
21236 KB |
Output is correct |
8 |
Correct |
63 ms |
21456 KB |
Output is correct |
9 |
Correct |
58 ms |
22104 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
5160 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
34 ms |
14988 KB |
Output is correct |
15 |
Correct |
124 ms |
22512 KB |
Output is correct |
16 |
Correct |
2 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
69 ms |
20536 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
34 ms |
14936 KB |
Output is correct |
24 |
Correct |
116 ms |
22512 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
69 ms |
27708 KB |
Output is correct |
28 |
Correct |
52 ms |
20596 KB |
Output is correct |
29 |
Correct |
53 ms |
18140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4936 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5164 KB |
Output is correct |
27 |
Correct |
2 ms |
5108 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
5156 KB |
Output is correct |
30 |
Correct |
2 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4952 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
5208 KB |
Output is correct |
14 |
Correct |
2 ms |
4952 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4952 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4936 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5164 KB |
Output is correct |
27 |
Correct |
2 ms |
5108 KB |
Output is correct |
28 |
Correct |
2 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
5156 KB |
Output is correct |
30 |
Correct |
2 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
4 ms |
5468 KB |
Output is correct |
34 |
Correct |
3 ms |
5468 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
4 ms |
5212 KB |
Output is correct |
37 |
Correct |
3 ms |
5168 KB |
Output is correct |
38 |
Correct |
3 ms |
5212 KB |
Output is correct |
39 |
Correct |
3 ms |
5212 KB |
Output is correct |
40 |
Correct |
3 ms |
5464 KB |
Output is correct |
41 |
Correct |
3 ms |
5424 KB |
Output is correct |
42 |
Correct |
3 ms |
5212 KB |
Output is correct |
43 |
Correct |
4 ms |
5460 KB |
Output is correct |
44 |
Correct |
3 ms |
5284 KB |
Output is correct |
45 |
Correct |
4 ms |
5212 KB |
Output is correct |
46 |
Correct |
3 ms |
5468 KB |
Output is correct |
47 |
Correct |
3 ms |
5168 KB |
Output is correct |
48 |
Correct |
3 ms |
5172 KB |
Output is correct |
49 |
Correct |
3 ms |
5212 KB |
Output is correct |
50 |
Correct |
3 ms |
5212 KB |
Output is correct |
51 |
Correct |
4 ms |
5264 KB |
Output is correct |
52 |
Correct |
3 ms |
5212 KB |
Output is correct |
53 |
Correct |
4 ms |
5468 KB |
Output is correct |
54 |
Correct |
4 ms |
5720 KB |
Output is correct |
55 |
Correct |
3 ms |
5208 KB |
Output is correct |
56 |
Correct |
3 ms |
5208 KB |
Output is correct |
57 |
Correct |
3 ms |
5212 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5244 KB |
Output is correct |
7 |
Correct |
55 ms |
21236 KB |
Output is correct |
8 |
Correct |
63 ms |
21456 KB |
Output is correct |
9 |
Correct |
58 ms |
22104 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
5160 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
34 ms |
14988 KB |
Output is correct |
15 |
Correct |
124 ms |
22512 KB |
Output is correct |
16 |
Correct |
2 ms |
5208 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
69 ms |
20536 KB |
Output is correct |
19 |
Correct |
2 ms |
4952 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
34 ms |
14936 KB |
Output is correct |
24 |
Correct |
116 ms |
22512 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
26 |
Correct |
3 ms |
5468 KB |
Output is correct |
27 |
Correct |
69 ms |
27708 KB |
Output is correct |
28 |
Correct |
52 ms |
20596 KB |
Output is correct |
29 |
Correct |
53 ms |
18140 KB |
Output is correct |
30 |
Correct |
2 ms |
4952 KB |
Output is correct |
31 |
Correct |
2 ms |
4952 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
2 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
2 ms |
4956 KB |
Output is correct |
36 |
Correct |
2 ms |
4956 KB |
Output is correct |
37 |
Correct |
2 ms |
4956 KB |
Output is correct |
38 |
Correct |
2 ms |
4956 KB |
Output is correct |
39 |
Correct |
2 ms |
4956 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
2 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
5208 KB |
Output is correct |
43 |
Correct |
2 ms |
4952 KB |
Output is correct |
44 |
Correct |
3 ms |
4956 KB |
Output is correct |
45 |
Correct |
2 ms |
4956 KB |
Output is correct |
46 |
Correct |
3 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4952 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
2 ms |
4956 KB |
Output is correct |
52 |
Correct |
2 ms |
4936 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
3 ms |
5164 KB |
Output is correct |
56 |
Correct |
2 ms |
5108 KB |
Output is correct |
57 |
Correct |
2 ms |
4956 KB |
Output is correct |
58 |
Correct |
2 ms |
5156 KB |
Output is correct |
59 |
Correct |
2 ms |
5212 KB |
Output is correct |
60 |
Correct |
2 ms |
4956 KB |
Output is correct |
61 |
Correct |
2 ms |
4956 KB |
Output is correct |
62 |
Correct |
4 ms |
5468 KB |
Output is correct |
63 |
Correct |
3 ms |
5468 KB |
Output is correct |
64 |
Correct |
2 ms |
5212 KB |
Output is correct |
65 |
Correct |
4 ms |
5212 KB |
Output is correct |
66 |
Correct |
3 ms |
5168 KB |
Output is correct |
67 |
Correct |
3 ms |
5212 KB |
Output is correct |
68 |
Correct |
3 ms |
5212 KB |
Output is correct |
69 |
Correct |
3 ms |
5464 KB |
Output is correct |
70 |
Correct |
3 ms |
5424 KB |
Output is correct |
71 |
Correct |
3 ms |
5212 KB |
Output is correct |
72 |
Correct |
4 ms |
5460 KB |
Output is correct |
73 |
Correct |
3 ms |
5284 KB |
Output is correct |
74 |
Correct |
4 ms |
5212 KB |
Output is correct |
75 |
Correct |
3 ms |
5468 KB |
Output is correct |
76 |
Correct |
3 ms |
5168 KB |
Output is correct |
77 |
Correct |
3 ms |
5172 KB |
Output is correct |
78 |
Correct |
3 ms |
5212 KB |
Output is correct |
79 |
Correct |
3 ms |
5212 KB |
Output is correct |
80 |
Correct |
4 ms |
5264 KB |
Output is correct |
81 |
Correct |
3 ms |
5212 KB |
Output is correct |
82 |
Correct |
4 ms |
5468 KB |
Output is correct |
83 |
Correct |
4 ms |
5720 KB |
Output is correct |
84 |
Correct |
3 ms |
5208 KB |
Output is correct |
85 |
Correct |
3 ms |
5208 KB |
Output is correct |
86 |
Correct |
3 ms |
5212 KB |
Output is correct |
87 |
Correct |
3 ms |
5212 KB |
Output is correct |
88 |
Correct |
94 ms |
23684 KB |
Output is correct |
89 |
Correct |
91 ms |
23560 KB |
Output is correct |
90 |
Correct |
97 ms |
23556 KB |
Output is correct |
91 |
Correct |
39 ms |
19028 KB |
Output is correct |
92 |
Correct |
40 ms |
19032 KB |
Output is correct |
93 |
Correct |
37 ms |
15696 KB |
Output is correct |
94 |
Correct |
49 ms |
15664 KB |
Output is correct |
95 |
Correct |
153 ms |
24720 KB |
Output is correct |
96 |
Correct |
136 ms |
24528 KB |
Output is correct |
97 |
Correct |
134 ms |
22972 KB |
Output is correct |
98 |
Correct |
124 ms |
23068 KB |
Output is correct |
99 |
Correct |
60 ms |
22096 KB |
Output is correct |
100 |
Correct |
60 ms |
21864 KB |
Output is correct |
101 |
Correct |
38 ms |
19024 KB |
Output is correct |
102 |
Correct |
44 ms |
19172 KB |
Output is correct |
103 |
Correct |
37 ms |
15700 KB |
Output is correct |
104 |
Correct |
37 ms |
15768 KB |
Output is correct |
105 |
Correct |
175 ms |
24496 KB |
Output is correct |
106 |
Correct |
153 ms |
24512 KB |
Output is correct |
107 |
Correct |
139 ms |
29096 KB |
Output is correct |
108 |
Correct |
140 ms |
29420 KB |
Output is correct |
109 |
Correct |
74 ms |
21648 KB |
Output is correct |
110 |
Correct |
66 ms |
21652 KB |
Output is correct |
111 |
Correct |
82 ms |
19424 KB |
Output is correct |
112 |
Correct |
86 ms |
19420 KB |
Output is correct |