답안 #366077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366077 2021-02-13T02:03:31 Z KoD 꿈 (IOI13_dreaming) C++17
65 / 100
171 ms 34156 KB
#ifndef __APPLE__
#include "dreaming.h"
#endif
#include <bits/stdc++.h>

template <class T>
using Vec = std::vector<T>;

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  Vec<Vec<std::pair<int, int>>> graph(N);
  for (int i = 0; i < M; ++i) {
    graph[A[i]].emplace_back(B[i], T[i]);
    graph[B[i]].emplace_back(A[i], T[i]);
  }
  Vec<bool> done(N);
  Vec<Vec<int>> max(N);
  for (int i = 0; i < N; ++i) {
    max[i].resize(graph[i].size());
  }
  auto dfs = [&](auto dfs, const int u) -> int {
    done[u] = true;
    int ret = 0;
    for (int i = 0; i < (int) graph[u].size(); ++i) {
      const auto [v, c] = graph[u][i];
      if (!done[v]) {
        max[u][i] = dfs(dfs, v) + c;
        ret = std::max(ret, max[u][i]);
      }
    }
    return ret;
  };
  int ans = 0;
  auto apply = [&](auto apply, const int u, const int p, const int up) -> int {
    for (int i = 0; i < (int) graph[u].size(); ++i) {
      const auto [v, c] = graph[u][i];
      if (v == p) {
        max[u][i] = up + c;
      }
    }
    Vec<int> pref(max[u].size() + 1);
    Vec<int> suff(max[u].size() + 1);
    for (int i = 0; i < (int) max[u].size(); ++i) {
      pref[i + 1] = std::max(pref[i], max[u][i]);
      suff[i + 1] = std::max(suff[i], max[u][max[u].size() - i - 1]);
    }
    int ret = pref[max[u].size()];
    ans = std::max(ans, ret);
    for (int i = 0; i < (int) graph[u].size(); ++i) {
      ans = std::max(ans, pref[i] + suff[max[u].size() - i]);
      const auto [v, c] = graph[u][i];
      if (v != p) {
        ret = std::min(ret, apply(apply, v, u, std::max(pref[i], suff[max[u].size() - i - 1])));
      }
    }
    return ret;
  };
  Vec<int> roots;
  for (int i = 0; i < N; ++i) {
    if (!done[i]) {
      dfs(dfs, i);
      roots.push_back(apply(apply, i, i, 0));
    }
  }
  std::sort(roots.begin(), roots.end());
  const auto center = roots.back();
  roots.pop_back();
  if (roots.empty()) {
    return center;
  }
  ans = std::max(ans, center + L + roots.back());
  Vec<int> pref(roots.size() + 1);
  Vec<int> suff(roots.size() + 1);
  for (int i = 0; i < (int) roots.size(); ++i) {
    pref[i + 1] = std::max(pref[i], roots[i]);
    suff[i + 1] = std::max(suff[i], roots[roots.size() - i - 1]);
  }
  for (int i = 1; i < (int) roots.size(); ++i) {
    ans = std::max(ans, pref[i] + suff[roots.size() - i] + 2 * L);
  }
  return ans;
}

#ifdef __APPLE__ 
int A[100];
int B[100];
int T[100];
int main() {
  int N, M, L;
  std::cin >> N >> M >> L;
  for (int i = 0; i < M; ++i) {
    std::cin >> A[i] >> B[i] >> T[i];
  }
  std::cout << travelTime(N, M, L, A, B, T) << '\n';
  return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 21612 KB Output is correct
2 Correct 102 ms 20844 KB Output is correct
3 Correct 69 ms 18028 KB Output is correct
4 Correct 12 ms 3436 KB Output is correct
5 Correct 10 ms 2156 KB Output is correct
6 Correct 20 ms 4972 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 41 ms 9708 KB Output is correct
9 Correct 62 ms 15084 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 101 ms 16876 KB Output is correct
12 Correct 126 ms 19692 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 21612 KB Output is correct
2 Correct 102 ms 20844 KB Output is correct
3 Correct 69 ms 18028 KB Output is correct
4 Correct 12 ms 3436 KB Output is correct
5 Correct 10 ms 2156 KB Output is correct
6 Correct 20 ms 4972 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 41 ms 9708 KB Output is correct
9 Correct 62 ms 15084 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 101 ms 16876 KB Output is correct
12 Correct 126 ms 19692 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 101 ms 23020 KB Output is correct
40 Correct 101 ms 22124 KB Output is correct
41 Correct 77 ms 19052 KB Output is correct
42 Correct 14 ms 3564 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 492 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 118 ms 14316 KB Output is correct
58 Correct 120 ms 14316 KB Output is correct
59 Correct 128 ms 14572 KB Output is correct
60 Correct 162 ms 14444 KB Output is correct
61 Correct 134 ms 14572 KB Output is correct
62 Correct 118 ms 14700 KB Output is correct
63 Correct 111 ms 14444 KB Output is correct
64 Correct 124 ms 14444 KB Output is correct
65 Correct 124 ms 14700 KB Output is correct
66 Correct 147 ms 14700 KB Output is correct
67 Correct 116 ms 14604 KB Output is correct
68 Correct 125 ms 14572 KB Output is correct
69 Correct 153 ms 14828 KB Output is correct
70 Correct 130 ms 14828 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 3 ms 748 KB Output is correct
73 Correct 3 ms 748 KB Output is correct
74 Correct 3 ms 748 KB Output is correct
75 Correct 3 ms 748 KB Output is correct
76 Correct 3 ms 748 KB Output is correct
77 Correct 3 ms 748 KB Output is correct
78 Correct 3 ms 748 KB Output is correct
79 Correct 3 ms 896 KB Output is correct
80 Correct 129 ms 14444 KB Output is correct
81 Correct 130 ms 14628 KB Output is correct
82 Correct 125 ms 14700 KB Output is correct
83 Correct 138 ms 14572 KB Output is correct
84 Correct 2 ms 620 KB Output is correct
85 Correct 2 ms 620 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 2 ms 748 KB Output is correct
88 Correct 3 ms 748 KB Output is correct
89 Correct 2 ms 748 KB Output is correct
90 Correct 2 ms 748 KB Output is correct
91 Correct 3 ms 748 KB Output is correct
92 Correct 2 ms 748 KB Output is correct
93 Correct 3 ms 748 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 1 ms 364 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 9 ms 2284 KB Output is correct
105 Correct 21 ms 5356 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 64 ms 9708 KB Output is correct
108 Correct 63 ms 15084 KB Output is correct
109 Correct 1 ms 512 KB Output is correct
110 Correct 87 ms 16768 KB Output is correct
111 Correct 111 ms 19788 KB Output is correct
112 Correct 1 ms 492 KB Output is correct
113 Correct 171 ms 34156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 9904 KB Output is correct
2 Correct 43 ms 9968 KB Output is correct
3 Correct 45 ms 9964 KB Output is correct
4 Correct 43 ms 9964 KB Output is correct
5 Correct 43 ms 9836 KB Output is correct
6 Correct 49 ms 10348 KB Output is correct
7 Correct 47 ms 10344 KB Output is correct
8 Correct 55 ms 9704 KB Output is correct
9 Correct 44 ms 9580 KB Output is correct
10 Correct 48 ms 10224 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 13 ms 6372 KB Output is correct
13 Correct 13 ms 6380 KB Output is correct
14 Correct 13 ms 6372 KB Output is correct
15 Correct 15 ms 6372 KB Output is correct
16 Correct 14 ms 6372 KB Output is correct
17 Correct 16 ms 6372 KB Output is correct
18 Correct 14 ms 6376 KB Output is correct
19 Correct 13 ms 6520 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 13 ms 6372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 620 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 2 ms 620 KB Output is correct
34 Correct 2 ms 748 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Incorrect 5 ms 1132 KB Output isn't correct
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 21612 KB Output is correct
2 Correct 102 ms 20844 KB Output is correct
3 Correct 69 ms 18028 KB Output is correct
4 Correct 12 ms 3436 KB Output is correct
5 Correct 10 ms 2156 KB Output is correct
6 Correct 20 ms 4972 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 41 ms 9708 KB Output is correct
9 Correct 62 ms 15084 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 101 ms 16876 KB Output is correct
12 Correct 126 ms 19692 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 101 ms 23020 KB Output is correct
40 Correct 101 ms 22124 KB Output is correct
41 Correct 77 ms 19052 KB Output is correct
42 Correct 14 ms 3564 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 492 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 118 ms 14316 KB Output is correct
58 Correct 120 ms 14316 KB Output is correct
59 Correct 128 ms 14572 KB Output is correct
60 Correct 162 ms 14444 KB Output is correct
61 Correct 134 ms 14572 KB Output is correct
62 Correct 118 ms 14700 KB Output is correct
63 Correct 111 ms 14444 KB Output is correct
64 Correct 124 ms 14444 KB Output is correct
65 Correct 124 ms 14700 KB Output is correct
66 Correct 147 ms 14700 KB Output is correct
67 Correct 116 ms 14604 KB Output is correct
68 Correct 125 ms 14572 KB Output is correct
69 Correct 153 ms 14828 KB Output is correct
70 Correct 130 ms 14828 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 3 ms 748 KB Output is correct
73 Correct 3 ms 748 KB Output is correct
74 Correct 3 ms 748 KB Output is correct
75 Correct 3 ms 748 KB Output is correct
76 Correct 3 ms 748 KB Output is correct
77 Correct 3 ms 748 KB Output is correct
78 Correct 3 ms 748 KB Output is correct
79 Correct 3 ms 896 KB Output is correct
80 Correct 129 ms 14444 KB Output is correct
81 Correct 130 ms 14628 KB Output is correct
82 Correct 125 ms 14700 KB Output is correct
83 Correct 138 ms 14572 KB Output is correct
84 Correct 2 ms 620 KB Output is correct
85 Correct 2 ms 620 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 2 ms 748 KB Output is correct
88 Correct 3 ms 748 KB Output is correct
89 Correct 2 ms 748 KB Output is correct
90 Correct 2 ms 748 KB Output is correct
91 Correct 3 ms 748 KB Output is correct
92 Correct 2 ms 748 KB Output is correct
93 Correct 3 ms 748 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 1 ms 364 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 9 ms 2284 KB Output is correct
105 Correct 21 ms 5356 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 64 ms 9708 KB Output is correct
108 Correct 63 ms 15084 KB Output is correct
109 Correct 1 ms 512 KB Output is correct
110 Correct 87 ms 16768 KB Output is correct
111 Correct 111 ms 19788 KB Output is correct
112 Correct 1 ms 492 KB Output is correct
113 Correct 171 ms 34156 KB Output is correct
114 Correct 69 ms 9904 KB Output is correct
115 Correct 43 ms 9968 KB Output is correct
116 Correct 45 ms 9964 KB Output is correct
117 Correct 43 ms 9964 KB Output is correct
118 Correct 43 ms 9836 KB Output is correct
119 Correct 49 ms 10348 KB Output is correct
120 Correct 47 ms 10344 KB Output is correct
121 Correct 55 ms 9704 KB Output is correct
122 Correct 44 ms 9580 KB Output is correct
123 Correct 48 ms 10224 KB Output is correct
124 Correct 0 ms 364 KB Output is correct
125 Correct 13 ms 6372 KB Output is correct
126 Correct 13 ms 6380 KB Output is correct
127 Correct 13 ms 6372 KB Output is correct
128 Correct 15 ms 6372 KB Output is correct
129 Correct 14 ms 6372 KB Output is correct
130 Correct 16 ms 6372 KB Output is correct
131 Correct 14 ms 6376 KB Output is correct
132 Correct 13 ms 6520 KB Output is correct
133 Correct 1 ms 364 KB Output is correct
134 Correct 1 ms 364 KB Output is correct
135 Correct 1 ms 492 KB Output is correct
136 Correct 13 ms 6372 KB Output is correct
137 Correct 1 ms 492 KB Output is correct
138 Correct 2 ms 620 KB Output is correct
139 Correct 2 ms 748 KB Output is correct
140 Correct 1 ms 492 KB Output is correct
141 Correct 2 ms 620 KB Output is correct
142 Correct 2 ms 748 KB Output is correct
143 Correct 1 ms 492 KB Output is correct
144 Correct 2 ms 620 KB Output is correct
145 Correct 2 ms 748 KB Output is correct
146 Correct 1 ms 364 KB Output is correct
147 Correct 1 ms 364 KB Output is correct
148 Correct 1 ms 364 KB Output is correct
149 Correct 1 ms 364 KB Output is correct
150 Correct 1 ms 364 KB Output is correct
151 Correct 1 ms 364 KB Output is correct
152 Correct 1 ms 364 KB Output is correct
153 Correct 1 ms 364 KB Output is correct
154 Correct 1 ms 364 KB Output is correct
155 Correct 1 ms 364 KB Output is correct
156 Correct 1 ms 364 KB Output is correct
157 Correct 1 ms 364 KB Output is correct
158 Correct 1 ms 364 KB Output is correct
159 Correct 1 ms 364 KB Output is correct
160 Correct 1 ms 364 KB Output is correct
161 Correct 1 ms 364 KB Output is correct
162 Correct 1 ms 364 KB Output is correct
163 Correct 1 ms 364 KB Output is correct
164 Correct 1 ms 364 KB Output is correct
165 Incorrect 5 ms 1132 KB Output isn't correct
166 Halted 0 ms 0 KB -