Submission #1089714

# Submission time Handle Problem Language Result Execution time Memory
1089714 2024-09-17T01:31:17 Z hahahaha Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
546 ms 29436 KB
#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) {
      |            ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 ms 344 KB Output is correct
7 Correct 0 ms 376 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 0 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 ms 344 KB Output is correct
7 Correct 0 ms 376 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 0 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 361 ms 6352 KB Output is correct
21 Correct 222 ms 6444 KB Output is correct
22 Correct 340 ms 6364 KB Output is correct
23 Correct 393 ms 6368 KB Output is correct
24 Correct 363 ms 6372 KB Output is correct
25 Correct 344 ms 6572 KB Output is correct
26 Correct 378 ms 6372 KB Output is correct
27 Correct 378 ms 6568 KB Output is correct
28 Correct 357 ms 6372 KB Output is correct
29 Correct 274 ms 6424 KB Output is correct
30 Correct 353 ms 6568 KB Output is correct
31 Correct 357 ms 6376 KB Output is correct
32 Correct 353 ms 6600 KB Output is correct
33 Correct 352 ms 6376 KB Output is correct
34 Correct 247 ms 7320 KB Output is correct
35 Correct 352 ms 6504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 542 ms 26432 KB Output is correct
5 Correct 531 ms 26564 KB Output is correct
6 Correct 546 ms 26552 KB Output is correct
7 Correct 206 ms 28352 KB Output is correct
8 Correct 197 ms 28600 KB Output is correct
9 Correct 200 ms 28604 KB Output is correct
10 Correct 542 ms 26612 KB Output is correct
11 Correct 197 ms 28648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 ms 344 KB Output is correct
7 Correct 0 ms 376 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 0 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 344 KB Output is correct
20 Correct 136 ms 22284 KB Output is correct
21 Correct 130 ms 22612 KB Output is correct
22 Correct 128 ms 22356 KB Output is correct
23 Correct 124 ms 22356 KB Output is correct
24 Correct 124 ms 22356 KB Output is correct
25 Correct 134 ms 22356 KB Output is correct
26 Correct 124 ms 22452 KB Output is correct
27 Correct 124 ms 22460 KB Output is correct
28 Correct 133 ms 22356 KB Output is correct
29 Correct 136 ms 22352 KB Output is correct
30 Correct 134 ms 22608 KB Output is correct
31 Correct 138 ms 22288 KB Output is correct
32 Correct 126 ms 23072 KB Output is correct
33 Correct 125 ms 22352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 ms 344 KB Output is correct
7 Correct 0 ms 376 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 0 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 361 ms 6352 KB Output is correct
21 Correct 222 ms 6444 KB Output is correct
22 Correct 340 ms 6364 KB Output is correct
23 Correct 393 ms 6368 KB Output is correct
24 Correct 363 ms 6372 KB Output is correct
25 Correct 344 ms 6572 KB Output is correct
26 Correct 378 ms 6372 KB Output is correct
27 Correct 378 ms 6568 KB Output is correct
28 Correct 357 ms 6372 KB Output is correct
29 Correct 274 ms 6424 KB Output is correct
30 Correct 353 ms 6568 KB Output is correct
31 Correct 357 ms 6376 KB Output is correct
32 Correct 353 ms 6600 KB Output is correct
33 Correct 352 ms 6376 KB Output is correct
34 Correct 247 ms 7320 KB Output is correct
35 Correct 352 ms 6504 KB Output is correct
36 Correct 364 ms 6940 KB Output is correct
37 Correct 235 ms 6624 KB Output is correct
38 Correct 428 ms 6876 KB Output is correct
39 Correct 396 ms 6628 KB Output is correct
40 Correct 372 ms 6632 KB Output is correct
41 Correct 343 ms 6628 KB Output is correct
42 Correct 373 ms 6768 KB Output is correct
43 Correct 354 ms 6636 KB Output is correct
44 Correct 359 ms 6632 KB Output is correct
45 Correct 261 ms 6656 KB Output is correct
46 Correct 363 ms 6604 KB Output is correct
47 Correct 356 ms 6632 KB Output is correct
48 Correct 372 ms 6772 KB Output is correct
49 Correct 372 ms 6636 KB Output is correct
50 Correct 250 ms 7420 KB Output is correct
51 Correct 358 ms 6628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 ms 344 KB Output is correct
7 Correct 0 ms 376 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 0 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 361 ms 6352 KB Output is correct
21 Correct 222 ms 6444 KB Output is correct
22 Correct 340 ms 6364 KB Output is correct
23 Correct 393 ms 6368 KB Output is correct
24 Correct 363 ms 6372 KB Output is correct
25 Correct 344 ms 6572 KB Output is correct
26 Correct 378 ms 6372 KB Output is correct
27 Correct 378 ms 6568 KB Output is correct
28 Correct 357 ms 6372 KB Output is correct
29 Correct 274 ms 6424 KB Output is correct
30 Correct 353 ms 6568 KB Output is correct
31 Correct 357 ms 6376 KB Output is correct
32 Correct 353 ms 6600 KB Output is correct
33 Correct 352 ms 6376 KB Output is correct
34 Correct 247 ms 7320 KB Output is correct
35 Correct 352 ms 6504 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 542 ms 26432 KB Output is correct
40 Correct 531 ms 26564 KB Output is correct
41 Correct 546 ms 26552 KB Output is correct
42 Correct 206 ms 28352 KB Output is correct
43 Correct 197 ms 28600 KB Output is correct
44 Correct 200 ms 28604 KB Output is correct
45 Correct 542 ms 26612 KB Output is correct
46 Correct 197 ms 28648 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 136 ms 22284 KB Output is correct
49 Correct 130 ms 22612 KB Output is correct
50 Correct 128 ms 22356 KB Output is correct
51 Correct 124 ms 22356 KB Output is correct
52 Correct 124 ms 22356 KB Output is correct
53 Correct 134 ms 22356 KB Output is correct
54 Correct 124 ms 22452 KB Output is correct
55 Correct 124 ms 22460 KB Output is correct
56 Correct 133 ms 22356 KB Output is correct
57 Correct 136 ms 22352 KB Output is correct
58 Correct 134 ms 22608 KB Output is correct
59 Correct 138 ms 22288 KB Output is correct
60 Correct 126 ms 23072 KB Output is correct
61 Correct 125 ms 22352 KB Output is correct
62 Correct 364 ms 6940 KB Output is correct
63 Correct 235 ms 6624 KB Output is correct
64 Correct 428 ms 6876 KB Output is correct
65 Correct 396 ms 6628 KB Output is correct
66 Correct 372 ms 6632 KB Output is correct
67 Correct 343 ms 6628 KB Output is correct
68 Correct 373 ms 6768 KB Output is correct
69 Correct 354 ms 6636 KB Output is correct
70 Correct 359 ms 6632 KB Output is correct
71 Correct 261 ms 6656 KB Output is correct
72 Correct 363 ms 6604 KB Output is correct
73 Correct 356 ms 6632 KB Output is correct
74 Correct 372 ms 6772 KB Output is correct
75 Correct 372 ms 6636 KB Output is correct
76 Correct 250 ms 7420 KB Output is correct
77 Correct 358 ms 6628 KB Output is correct
78 Correct 521 ms 25564 KB Output is correct
79 Correct 347 ms 27444 KB Output is correct
80 Correct 465 ms 26332 KB Output is correct
81 Correct 494 ms 26372 KB Output is correct
82 Correct 488 ms 25564 KB Output is correct
83 Correct 471 ms 25564 KB Output is correct
84 Correct 485 ms 25572 KB Output is correct
85 Correct 474 ms 25584 KB Output is correct
86 Correct 469 ms 25584 KB Output is correct
87 Correct 391 ms 27128 KB Output is correct
88 Correct 487 ms 25440 KB Output is correct
89 Correct 506 ms 25572 KB Output is correct
90 Correct 502 ms 25516 KB Output is correct
91 Correct 496 ms 25252 KB Output is correct
92 Correct 396 ms 29436 KB Output is correct
93 Correct 476 ms 26540 KB Output is correct