Submission #979192

# Submission time Handle Problem Language Result Execution time Memory
979192 2024-05-10T11:10:28 Z kilkuwu Dreaming (IOI13_dreaming) C++17
47 / 100
51 ms 21036 KB
#include "dreaming.h"
#include <bits/stdc++.h>

#ifdef LOCAL
#include "template/debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif

template <typename T>
inline bool ckmin(T& x, const T& y) {
  return y < x ? x = y, 1 : 0;
}

template <typename T>
inline bool ckmax(T& x, const T& y) {
  return x < y ? x = y, 1 : 0;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  dbg(N, M, L);

  auto merge = [&](int a, int b, int w) {
    int left = std::max(a, w + b);
    int right = std::max(b, w + a);
    return std::min(left, right);
  };

  std::vector<std::vector<std::pair<int, int>>> adj(N);
  for (int i = 0; i < M; i++) {
    dbg(A[i], B[i], T[i]);
    adj[A[i]].emplace_back(B[i], T[i]);
    adj[B[i]].emplace_back(A[i], T[i]);
  }


  std::priority_queue<int, std::vector<int>, std::greater<int>> pq;

  std::vector<int> vis(N), comp;
  std::vector<int> dp(N);
  std::vector<int> up(N);

  auto dfs1 = [&](auto self, int u, int p) -> void {
    comp.push_back(u);
    vis[u] = 1;
    dp[u] = 0;

    for (auto [v, w] : adj[u]) {
      if (v == p) continue;
      self(self, v, u);
      ckmax(dp[u], dp[v] + w);
    }
  };

  int max_val = 0;

  for (int i = 0; i < N; i++) {
    if (vis[i]) continue;

    auto dfs2 = [&](auto self, int u, int p) -> int {
      int lmao = std::max(up[u], dp[u]);
      ckmax(max_val, lmao);
      std::pair<int, int> good = {0, 0};

      for (auto [v, w] : adj[u]) {
        if (v == p) continue;
        if (w + dp[v] > good.first) {
          good.second = good.first;
          good.first = w + dp[v];
        } else if (w + dp[v] > good.second) {
          good.second = w + dp[v];
        }
      }

      for (auto [v, w] : adj[u]) {
        if (v == p) continue;
        up[v] = w + std::max(up[u], good.first == w + dp[v] ? good.second
                                                            : good.first);
        ckmin(lmao, self(self, v, u));
      }

      return lmao;
    };

    dfs1(dfs1, i, i);
    pq.push(dfs2(dfs2, i, i));
  }

  dbg(max_val);

  dbg(pq);

  dbg(pq.size());
  
  while (pq.size() > 1) {
    auto best1 = pq.top();
    pq.pop();

    auto best2 = pq.top();
    pq.pop();
    dbg(best1, best2);
    ckmax(max_val, best1 + best2 + L);

    pq.push(merge(best1, best2, L));
  }

  return max_val;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 14544 KB Output is correct
2 Correct 37 ms 14032 KB Output is correct
3 Correct 25 ms 12064 KB Output is correct
4 Correct 5 ms 2396 KB Output is correct
5 Correct 4 ms 1624 KB Output is correct
6 Correct 9 ms 3672 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 17 ms 6140 KB Output is correct
9 Correct 28 ms 9368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 31 ms 10644 KB Output is correct
12 Correct 36 ms 12252 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 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 1 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 544 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 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 14544 KB Output is correct
2 Correct 37 ms 14032 KB Output is correct
3 Correct 25 ms 12064 KB Output is correct
4 Correct 5 ms 2396 KB Output is correct
5 Correct 4 ms 1624 KB Output is correct
6 Correct 9 ms 3672 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 17 ms 6140 KB Output is correct
9 Correct 28 ms 9368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 31 ms 10644 KB Output is correct
12 Correct 36 ms 12252 KB Output is correct
13 Correct 1 ms 344 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 344 KB Output is correct
17 Correct 1 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 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 348 KB Output is correct
28 Correct 0 ms 348 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 544 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 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 36 ms 14288 KB Output is correct
40 Correct 35 ms 14040 KB Output is correct
41 Correct 25 ms 11980 KB Output is correct
42 Correct 5 ms 2396 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 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 348 KB Output is correct
52 Correct 0 ms 444 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 42 ms 9936 KB Output is correct
58 Correct 41 ms 9936 KB Output is correct
59 Correct 41 ms 9936 KB Output is correct
60 Correct 42 ms 9932 KB Output is correct
61 Correct 41 ms 9964 KB Output is correct
62 Correct 45 ms 9944 KB Output is correct
63 Correct 38 ms 9628 KB Output is correct
64 Correct 38 ms 9684 KB Output is correct
65 Correct 41 ms 9956 KB Output is correct
66 Correct 43 ms 9936 KB Output is correct
67 Correct 42 ms 9988 KB Output is correct
68 Correct 41 ms 9676 KB Output is correct
69 Correct 42 ms 9972 KB Output is correct
70 Correct 43 ms 9944 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 44 ms 10096 KB Output is correct
81 Correct 41 ms 9936 KB Output is correct
82 Correct 42 ms 9684 KB Output is correct
83 Correct 41 ms 9676 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 1 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 1 ms 348 KB Output is correct
104 Correct 4 ms 1628 KB Output is correct
105 Correct 8 ms 3436 KB Output is correct
106 Correct 1 ms 600 KB Output is correct
107 Correct 16 ms 6212 KB Output is correct
108 Correct 22 ms 9432 KB Output is correct
109 Correct 0 ms 344 KB Output is correct
110 Correct 30 ms 10700 KB Output is correct
111 Correct 35 ms 12296 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 51 ms 21036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 7124 KB Output is correct
2 Incorrect 23 ms 6872 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 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 1 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 544 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 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 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 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 14544 KB Output is correct
2 Correct 37 ms 14032 KB Output is correct
3 Correct 25 ms 12064 KB Output is correct
4 Correct 5 ms 2396 KB Output is correct
5 Correct 4 ms 1624 KB Output is correct
6 Correct 9 ms 3672 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 17 ms 6140 KB Output is correct
9 Correct 28 ms 9368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 31 ms 10644 KB Output is correct
12 Correct 36 ms 12252 KB Output is correct
13 Correct 1 ms 344 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 344 KB Output is correct
17 Correct 1 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 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 348 KB Output is correct
28 Correct 0 ms 348 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 544 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 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 36 ms 14288 KB Output is correct
40 Correct 35 ms 14040 KB Output is correct
41 Correct 25 ms 11980 KB Output is correct
42 Correct 5 ms 2396 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 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 348 KB Output is correct
52 Correct 0 ms 444 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 42 ms 9936 KB Output is correct
58 Correct 41 ms 9936 KB Output is correct
59 Correct 41 ms 9936 KB Output is correct
60 Correct 42 ms 9932 KB Output is correct
61 Correct 41 ms 9964 KB Output is correct
62 Correct 45 ms 9944 KB Output is correct
63 Correct 38 ms 9628 KB Output is correct
64 Correct 38 ms 9684 KB Output is correct
65 Correct 41 ms 9956 KB Output is correct
66 Correct 43 ms 9936 KB Output is correct
67 Correct 42 ms 9988 KB Output is correct
68 Correct 41 ms 9676 KB Output is correct
69 Correct 42 ms 9972 KB Output is correct
70 Correct 43 ms 9944 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 44 ms 10096 KB Output is correct
81 Correct 41 ms 9936 KB Output is correct
82 Correct 42 ms 9684 KB Output is correct
83 Correct 41 ms 9676 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 1 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 1 ms 348 KB Output is correct
104 Correct 4 ms 1628 KB Output is correct
105 Correct 8 ms 3436 KB Output is correct
106 Correct 1 ms 600 KB Output is correct
107 Correct 16 ms 6212 KB Output is correct
108 Correct 22 ms 9432 KB Output is correct
109 Correct 0 ms 344 KB Output is correct
110 Correct 30 ms 10700 KB Output is correct
111 Correct 35 ms 12296 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 51 ms 21036 KB Output is correct
114 Correct 26 ms 7124 KB Output is correct
115 Incorrect 23 ms 6872 KB Output isn't correct
116 Halted 0 ms 0 KB -