#include <stdio.h>
#define NN 200000
#define MM 200000
int n, m, l, src, dst, nxt[MM*2+1], hed[NN], cst[MM*2+1], to[MM*2+1];
long long k, dp[NN], dsrc[NN], ddst[NN], answer;
const long long oo = 1e18;
void lnk(int u, int v, int w) {
static int ii = 1, i;
i = ii++;
cst[i] = w;
to[i] = v;
nxt[i] = hed[u];
hed[u] = i;
}
int tt[NN<<1];
int (*min)(int, int);
int mindijk(int i, int j) {
return dp[i] < dp[j] ? i : j;
}
int minddst(int i, int j) {
return ddst[i] < ddst[j] ? i : j;
}
void pul(int i) {
tt[i] = min(tt[i << 1], tt[i << 1 | 1]);
}
void fix(int i) {
for (i += n; i >>= 1;)
pul(i);
}
void dijkstra(int src, long long *out) {
int i;
for (i = 0; i < n; ++i)
dp[i] = oo, tt[i + n] = i;
dp[src] = 0;
for (i = n; --i;)
pul(i);
for (i = 0; i < n; ++i) {
int u, j;
u = tt[1];
out[u] = dp[u];
dp[u] = oo + 1;
fix(u);
for (j = hed[u]; j; j = nxt[j]) {
int v, w;
v = to[j], w = cst[j];
if (dp[v] == oo + 1)
continue;
if (dp[v] > out[u] + w)
dp[v] = out[u] + w, fix(v);
}
}
}
int main() {
int i, a, b, c;
scanf("%d%d%d%d%d%lld", &n, &m, &src, &dst, &l, &k);
--src, --dst;
for (i = 0; i < m; ++i)
scanf("%d%d%d", &a, &b, &c), lnk(--a, --b, c), lnk(b, a, c);
min = mindijk;
dijkstra(src, dsrc);
if (dsrc[dst] <= k) {
printf("%lld", n * (n - 1ll) / 2);
return 0;
}
dijkstra(dst, ddst);
min = minddst;
for (i = 0; i < n; ++i)
tt[i + n] = i;
for (i = n; --i;)
pul(i);
for (i = 0; i < n; ++i) {
dp[i] = ddst[tt[1]];
ddst[tt[1]] = oo + 1;
fix(tt[1]);
}
for (i = 0; i < n; ++i) {
int lower, upper, mid;
lower = -1;
upper = n;
while (upper - lower > 1) {
mid = lower + (upper - lower) / 2;
if (l + dp[mid] + dsrc[i] <= k)
lower = mid;
else
upper = mid;
}
answer += lower + 1;
}
printf("%lld", answer);
}
Compilation message
Main.c: In function 'main':
Main.c:68:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d%d%d%d%d%lld", &n, &m, &src, &dst, &l, &k);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:71:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%d%d%d", &a, &b, &c), lnk(--a, --b, c), lnk(b, a, c);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
103 ms |
14076 KB |
Output is correct |
8 |
Correct |
112 ms |
14204 KB |
Output is correct |
9 |
Correct |
55 ms |
13916 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8636 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
84 ms |
12676 KB |
Output is correct |
15 |
Correct |
134 ms |
15184 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
120 ms |
14928 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8636 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
85 ms |
12720 KB |
Output is correct |
24 |
Correct |
134 ms |
14928 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
61 ms |
14916 KB |
Output is correct |
28 |
Correct |
92 ms |
13652 KB |
Output is correct |
29 |
Correct |
92 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8564 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8620 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8536 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
31 |
Correct |
1 ms |
8628 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8564 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8620 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
8536 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
31 |
Correct |
1 ms |
8628 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
33 |
Correct |
2 ms |
8536 KB |
Output is correct |
34 |
Correct |
1 ms |
8540 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8696 KB |
Output is correct |
37 |
Correct |
2 ms |
8740 KB |
Output is correct |
38 |
Correct |
2 ms |
8540 KB |
Output is correct |
39 |
Correct |
2 ms |
8536 KB |
Output is correct |
40 |
Correct |
2 ms |
8536 KB |
Output is correct |
41 |
Correct |
1 ms |
8540 KB |
Output is correct |
42 |
Correct |
2 ms |
8536 KB |
Output is correct |
43 |
Correct |
2 ms |
8536 KB |
Output is correct |
44 |
Correct |
3 ms |
8632 KB |
Output is correct |
45 |
Correct |
2 ms |
8632 KB |
Output is correct |
46 |
Correct |
2 ms |
8536 KB |
Output is correct |
47 |
Correct |
2 ms |
8540 KB |
Output is correct |
48 |
Correct |
2 ms |
8540 KB |
Output is correct |
49 |
Correct |
1 ms |
8540 KB |
Output is correct |
50 |
Correct |
2 ms |
8700 KB |
Output is correct |
51 |
Correct |
3 ms |
8536 KB |
Output is correct |
52 |
Correct |
2 ms |
8540 KB |
Output is correct |
53 |
Correct |
2 ms |
8540 KB |
Output is correct |
54 |
Correct |
2 ms |
8540 KB |
Output is correct |
55 |
Correct |
2 ms |
8540 KB |
Output is correct |
56 |
Correct |
2 ms |
8540 KB |
Output is correct |
57 |
Correct |
2 ms |
8540 KB |
Output is correct |
58 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
103 ms |
14076 KB |
Output is correct |
8 |
Correct |
112 ms |
14204 KB |
Output is correct |
9 |
Correct |
55 ms |
13916 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8636 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
84 ms |
12676 KB |
Output is correct |
15 |
Correct |
134 ms |
15184 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
120 ms |
14928 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8636 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
85 ms |
12720 KB |
Output is correct |
24 |
Correct |
134 ms |
14928 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
61 ms |
14916 KB |
Output is correct |
28 |
Correct |
92 ms |
13652 KB |
Output is correct |
29 |
Correct |
92 ms |
14416 KB |
Output is correct |
30 |
Correct |
1 ms |
8540 KB |
Output is correct |
31 |
Correct |
1 ms |
8540 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
33 |
Correct |
1 ms |
8540 KB |
Output is correct |
34 |
Correct |
1 ms |
8540 KB |
Output is correct |
35 |
Correct |
1 ms |
8540 KB |
Output is correct |
36 |
Correct |
1 ms |
8536 KB |
Output is correct |
37 |
Correct |
1 ms |
8536 KB |
Output is correct |
38 |
Correct |
1 ms |
8540 KB |
Output is correct |
39 |
Correct |
1 ms |
8540 KB |
Output is correct |
40 |
Correct |
1 ms |
8540 KB |
Output is correct |
41 |
Correct |
1 ms |
8540 KB |
Output is correct |
42 |
Correct |
1 ms |
8540 KB |
Output is correct |
43 |
Correct |
1 ms |
8540 KB |
Output is correct |
44 |
Correct |
1 ms |
8564 KB |
Output is correct |
45 |
Correct |
1 ms |
8540 KB |
Output is correct |
46 |
Correct |
1 ms |
8540 KB |
Output is correct |
47 |
Correct |
1 ms |
8540 KB |
Output is correct |
48 |
Correct |
1 ms |
8540 KB |
Output is correct |
49 |
Correct |
1 ms |
8540 KB |
Output is correct |
50 |
Correct |
1 ms |
8540 KB |
Output is correct |
51 |
Correct |
1 ms |
8540 KB |
Output is correct |
52 |
Correct |
1 ms |
8540 KB |
Output is correct |
53 |
Correct |
1 ms |
8540 KB |
Output is correct |
54 |
Correct |
1 ms |
8540 KB |
Output is correct |
55 |
Correct |
1 ms |
8540 KB |
Output is correct |
56 |
Correct |
1 ms |
8620 KB |
Output is correct |
57 |
Correct |
1 ms |
8540 KB |
Output is correct |
58 |
Correct |
1 ms |
8536 KB |
Output is correct |
59 |
Correct |
1 ms |
8540 KB |
Output is correct |
60 |
Correct |
1 ms |
8628 KB |
Output is correct |
61 |
Correct |
1 ms |
8540 KB |
Output is correct |
62 |
Correct |
2 ms |
8536 KB |
Output is correct |
63 |
Correct |
1 ms |
8540 KB |
Output is correct |
64 |
Correct |
2 ms |
8540 KB |
Output is correct |
65 |
Correct |
2 ms |
8696 KB |
Output is correct |
66 |
Correct |
2 ms |
8740 KB |
Output is correct |
67 |
Correct |
2 ms |
8540 KB |
Output is correct |
68 |
Correct |
2 ms |
8536 KB |
Output is correct |
69 |
Correct |
2 ms |
8536 KB |
Output is correct |
70 |
Correct |
1 ms |
8540 KB |
Output is correct |
71 |
Correct |
2 ms |
8536 KB |
Output is correct |
72 |
Correct |
2 ms |
8536 KB |
Output is correct |
73 |
Correct |
3 ms |
8632 KB |
Output is correct |
74 |
Correct |
2 ms |
8632 KB |
Output is correct |
75 |
Correct |
2 ms |
8536 KB |
Output is correct |
76 |
Correct |
2 ms |
8540 KB |
Output is correct |
77 |
Correct |
2 ms |
8540 KB |
Output is correct |
78 |
Correct |
1 ms |
8540 KB |
Output is correct |
79 |
Correct |
2 ms |
8700 KB |
Output is correct |
80 |
Correct |
3 ms |
8536 KB |
Output is correct |
81 |
Correct |
2 ms |
8540 KB |
Output is correct |
82 |
Correct |
2 ms |
8540 KB |
Output is correct |
83 |
Correct |
2 ms |
8540 KB |
Output is correct |
84 |
Correct |
2 ms |
8540 KB |
Output is correct |
85 |
Correct |
2 ms |
8540 KB |
Output is correct |
86 |
Correct |
2 ms |
8540 KB |
Output is correct |
87 |
Correct |
2 ms |
8540 KB |
Output is correct |
88 |
Correct |
80 ms |
16728 KB |
Output is correct |
89 |
Correct |
75 ms |
16724 KB |
Output is correct |
90 |
Correct |
119 ms |
16724 KB |
Output is correct |
91 |
Correct |
40 ms |
13612 KB |
Output is correct |
92 |
Correct |
46 ms |
13528 KB |
Output is correct |
93 |
Correct |
88 ms |
13392 KB |
Output is correct |
94 |
Correct |
90 ms |
13500 KB |
Output is correct |
95 |
Correct |
161 ms |
16592 KB |
Output is correct |
96 |
Correct |
77 ms |
16408 KB |
Output is correct |
97 |
Correct |
195 ms |
16468 KB |
Output is correct |
98 |
Correct |
161 ms |
16468 KB |
Output is correct |
99 |
Correct |
119 ms |
16468 KB |
Output is correct |
100 |
Correct |
123 ms |
16464 KB |
Output is correct |
101 |
Correct |
50 ms |
13644 KB |
Output is correct |
102 |
Correct |
49 ms |
13652 KB |
Output is correct |
103 |
Correct |
88 ms |
13400 KB |
Output is correct |
104 |
Correct |
88 ms |
13396 KB |
Output is correct |
105 |
Correct |
162 ms |
16468 KB |
Output is correct |
106 |
Correct |
165 ms |
16588 KB |
Output is correct |
107 |
Correct |
136 ms |
16472 KB |
Output is correct |
108 |
Correct |
138 ms |
16468 KB |
Output is correct |
109 |
Correct |
82 ms |
14928 KB |
Output is correct |
110 |
Correct |
80 ms |
14752 KB |
Output is correct |
111 |
Correct |
96 ms |
14672 KB |
Output is correct |
112 |
Correct |
92 ms |
14672 KB |
Output is correct |