#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 505, M = 1e5 + 5, inf = 1e9;
int n, m, q;
int mn[N];
vector<array<int, 2>> g[N];
array<int, 3> edges[M];
void add(int u, int v, int w) {
g[u].push_back({v, w});
g[v].push_back({u, w});
}
void ers(int u, int v, int w) {
g[u].erase(find(g[u].begin(), g[u].end(), array<int, 2>{v, w}));
g[v].erase(find(g[v].begin(), g[v].end(), array<int, 2>{u, w}));
}
void dfs(int u, int p) {
for (auto [v, w] : g[u]) {
if (v != p) {
mn[v] = min(mn[u], w);
dfs(v, u);
}
}
}
int get(int u, int v) {
fill(mn + 1, mn + n + 1, m + 1);
dfs(u, u);
return mn[v];
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> edges[i][1] >> edges[i][2] >> edges[i][0];
}
sort(edges + 1, edges + m + 1);
vector<array<int, 3>> events;
for (int i = 1; i <= m; ++i) {
auto [c, u, v] = edges[i];
int lt = get(u, v);
if (lt != m + 1) {
auto [w, x, y] = edges[lt];
int md = (w + 1 + c) / 2;
events.push_back({md, w + c, -2});
ers(x, y, lt);
} else {
events.push_back({0, c, -1});
}
events.push_back({c, -2 * c, 2});
add(u, v, i);
}
sort(events.begin(), events.end());
cin >> q;
int j = 0, B = 0;
long long A = 0;
while (q--) {
int X; cin >> X;
while (j < events.size() && events[j][0] <= X) {
A += events[j][1];
B += events[j][2];
++j;
}
cout << (long long) B * X + A << "\n";
}
return 0;
}
Compilation message
reconstruction.cpp: In function 'int main()':
reconstruction.cpp:72:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | while (j < events.size() && events[j][0] <= X) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
480 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
480 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
480 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
480 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
374 ms |
6336 KB |
Output is correct |
21 |
Correct |
227 ms |
6880 KB |
Output is correct |
22 |
Correct |
343 ms |
6232 KB |
Output is correct |
23 |
Correct |
316 ms |
7648 KB |
Output is correct |
24 |
Correct |
364 ms |
6368 KB |
Output is correct |
25 |
Correct |
336 ms |
6372 KB |
Output is correct |
26 |
Correct |
327 ms |
6280 KB |
Output is correct |
27 |
Correct |
334 ms |
6376 KB |
Output is correct |
28 |
Correct |
319 ms |
6284 KB |
Output is correct |
29 |
Correct |
245 ms |
6400 KB |
Output is correct |
30 |
Correct |
323 ms |
6420 KB |
Output is correct |
31 |
Correct |
353 ms |
6376 KB |
Output is correct |
32 |
Correct |
332 ms |
6380 KB |
Output is correct |
33 |
Correct |
355 ms |
6320 KB |
Output is correct |
34 |
Correct |
233 ms |
7168 KB |
Output is correct |
35 |
Correct |
363 ms |
6340 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 |
546 ms |
23996 KB |
Output is correct |
5 |
Correct |
531 ms |
24044 KB |
Output is correct |
6 |
Correct |
515 ms |
24524 KB |
Output is correct |
7 |
Correct |
171 ms |
26052 KB |
Output is correct |
8 |
Correct |
192 ms |
26492 KB |
Output is correct |
9 |
Correct |
192 ms |
26064 KB |
Output is correct |
10 |
Correct |
559 ms |
24012 KB |
Output is correct |
11 |
Correct |
200 ms |
26072 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
480 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
480 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
480 KB |
Output is correct |
20 |
Correct |
133 ms |
20324 KB |
Output is correct |
21 |
Correct |
156 ms |
20524 KB |
Output is correct |
22 |
Correct |
148 ms |
20476 KB |
Output is correct |
23 |
Correct |
122 ms |
20456 KB |
Output is correct |
24 |
Correct |
130 ms |
20324 KB |
Output is correct |
25 |
Correct |
127 ms |
20308 KB |
Output is correct |
26 |
Correct |
113 ms |
20304 KB |
Output is correct |
27 |
Correct |
127 ms |
20284 KB |
Output is correct |
28 |
Correct |
117 ms |
20220 KB |
Output is correct |
29 |
Correct |
118 ms |
20312 KB |
Output is correct |
30 |
Correct |
118 ms |
21584 KB |
Output is correct |
31 |
Correct |
122 ms |
21484 KB |
Output is correct |
32 |
Correct |
119 ms |
22100 KB |
Output is correct |
33 |
Correct |
118 ms |
21328 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
480 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
480 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
374 ms |
6336 KB |
Output is correct |
21 |
Correct |
227 ms |
6880 KB |
Output is correct |
22 |
Correct |
343 ms |
6232 KB |
Output is correct |
23 |
Correct |
316 ms |
7648 KB |
Output is correct |
24 |
Correct |
364 ms |
6368 KB |
Output is correct |
25 |
Correct |
336 ms |
6372 KB |
Output is correct |
26 |
Correct |
327 ms |
6280 KB |
Output is correct |
27 |
Correct |
334 ms |
6376 KB |
Output is correct |
28 |
Correct |
319 ms |
6284 KB |
Output is correct |
29 |
Correct |
245 ms |
6400 KB |
Output is correct |
30 |
Correct |
323 ms |
6420 KB |
Output is correct |
31 |
Correct |
353 ms |
6376 KB |
Output is correct |
32 |
Correct |
332 ms |
6380 KB |
Output is correct |
33 |
Correct |
355 ms |
6320 KB |
Output is correct |
34 |
Correct |
233 ms |
7168 KB |
Output is correct |
35 |
Correct |
363 ms |
6340 KB |
Output is correct |
36 |
Correct |
352 ms |
6628 KB |
Output is correct |
37 |
Correct |
209 ms |
6620 KB |
Output is correct |
38 |
Correct |
321 ms |
6628 KB |
Output is correct |
39 |
Correct |
338 ms |
6628 KB |
Output is correct |
40 |
Correct |
353 ms |
6628 KB |
Output is correct |
41 |
Correct |
332 ms |
6680 KB |
Output is correct |
42 |
Correct |
335 ms |
6632 KB |
Output is correct |
43 |
Correct |
341 ms |
6664 KB |
Output is correct |
44 |
Correct |
316 ms |
6628 KB |
Output is correct |
45 |
Correct |
284 ms |
7684 KB |
Output is correct |
46 |
Correct |
365 ms |
6628 KB |
Output is correct |
47 |
Correct |
369 ms |
6636 KB |
Output is correct |
48 |
Correct |
376 ms |
6764 KB |
Output is correct |
49 |
Correct |
357 ms |
6736 KB |
Output is correct |
50 |
Correct |
284 ms |
7380 KB |
Output is correct |
51 |
Correct |
394 ms |
6624 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
480 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
480 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
374 ms |
6336 KB |
Output is correct |
21 |
Correct |
227 ms |
6880 KB |
Output is correct |
22 |
Correct |
343 ms |
6232 KB |
Output is correct |
23 |
Correct |
316 ms |
7648 KB |
Output is correct |
24 |
Correct |
364 ms |
6368 KB |
Output is correct |
25 |
Correct |
336 ms |
6372 KB |
Output is correct |
26 |
Correct |
327 ms |
6280 KB |
Output is correct |
27 |
Correct |
334 ms |
6376 KB |
Output is correct |
28 |
Correct |
319 ms |
6284 KB |
Output is correct |
29 |
Correct |
245 ms |
6400 KB |
Output is correct |
30 |
Correct |
323 ms |
6420 KB |
Output is correct |
31 |
Correct |
353 ms |
6376 KB |
Output is correct |
32 |
Correct |
332 ms |
6380 KB |
Output is correct |
33 |
Correct |
355 ms |
6320 KB |
Output is correct |
34 |
Correct |
233 ms |
7168 KB |
Output is correct |
35 |
Correct |
363 ms |
6340 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 |
546 ms |
23996 KB |
Output is correct |
40 |
Correct |
531 ms |
24044 KB |
Output is correct |
41 |
Correct |
515 ms |
24524 KB |
Output is correct |
42 |
Correct |
171 ms |
26052 KB |
Output is correct |
43 |
Correct |
192 ms |
26492 KB |
Output is correct |
44 |
Correct |
192 ms |
26064 KB |
Output is correct |
45 |
Correct |
559 ms |
24012 KB |
Output is correct |
46 |
Correct |
200 ms |
26072 KB |
Output is correct |
47 |
Correct |
0 ms |
480 KB |
Output is correct |
48 |
Correct |
133 ms |
20324 KB |
Output is correct |
49 |
Correct |
156 ms |
20524 KB |
Output is correct |
50 |
Correct |
148 ms |
20476 KB |
Output is correct |
51 |
Correct |
122 ms |
20456 KB |
Output is correct |
52 |
Correct |
130 ms |
20324 KB |
Output is correct |
53 |
Correct |
127 ms |
20308 KB |
Output is correct |
54 |
Correct |
113 ms |
20304 KB |
Output is correct |
55 |
Correct |
127 ms |
20284 KB |
Output is correct |
56 |
Correct |
117 ms |
20220 KB |
Output is correct |
57 |
Correct |
118 ms |
20312 KB |
Output is correct |
58 |
Correct |
118 ms |
21584 KB |
Output is correct |
59 |
Correct |
122 ms |
21484 KB |
Output is correct |
60 |
Correct |
119 ms |
22100 KB |
Output is correct |
61 |
Correct |
118 ms |
21328 KB |
Output is correct |
62 |
Correct |
352 ms |
6628 KB |
Output is correct |
63 |
Correct |
209 ms |
6620 KB |
Output is correct |
64 |
Correct |
321 ms |
6628 KB |
Output is correct |
65 |
Correct |
338 ms |
6628 KB |
Output is correct |
66 |
Correct |
353 ms |
6628 KB |
Output is correct |
67 |
Correct |
332 ms |
6680 KB |
Output is correct |
68 |
Correct |
335 ms |
6632 KB |
Output is correct |
69 |
Correct |
341 ms |
6664 KB |
Output is correct |
70 |
Correct |
316 ms |
6628 KB |
Output is correct |
71 |
Correct |
284 ms |
7684 KB |
Output is correct |
72 |
Correct |
365 ms |
6628 KB |
Output is correct |
73 |
Correct |
369 ms |
6636 KB |
Output is correct |
74 |
Correct |
376 ms |
6764 KB |
Output is correct |
75 |
Correct |
357 ms |
6736 KB |
Output is correct |
76 |
Correct |
284 ms |
7380 KB |
Output is correct |
77 |
Correct |
394 ms |
6624 KB |
Output is correct |
78 |
Correct |
494 ms |
24600 KB |
Output is correct |
79 |
Correct |
336 ms |
26580 KB |
Output is correct |
80 |
Correct |
506 ms |
25644 KB |
Output is correct |
81 |
Correct |
545 ms |
25640 KB |
Output is correct |
82 |
Correct |
525 ms |
25032 KB |
Output is correct |
83 |
Correct |
525 ms |
24648 KB |
Output is correct |
84 |
Correct |
487 ms |
24544 KB |
Output is correct |
85 |
Correct |
476 ms |
24544 KB |
Output is correct |
86 |
Correct |
491 ms |
24644 KB |
Output is correct |
87 |
Correct |
426 ms |
26096 KB |
Output is correct |
88 |
Correct |
547 ms |
23088 KB |
Output is correct |
89 |
Correct |
567 ms |
23008 KB |
Output is correct |
90 |
Correct |
506 ms |
23040 KB |
Output is correct |
91 |
Correct |
519 ms |
22896 KB |
Output is correct |
92 |
Correct |
433 ms |
26916 KB |
Output is correct |
93 |
Correct |
482 ms |
24100 KB |
Output is correct |