답안 #492064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492064 2021-12-05T11:12:03 Z lorenzoferrari 꿈 (IOI13_dreaming) C++14
22 / 100
1000 ms 11844 KB
#include <bits/stdc++.h>
#ifndef LORENZO
#include "dreaming.h"
#endif
using namespace std;
using ll = long long;

array<int, 2> dmax;
vector<int> id, d;
vector<vector<int>> cc;
vector<vector<pair<int, int>>> g;

void comps(int v) {
  if (id[v] != -1) return;
  id[v] = cc.size() - 1;
  cc.back().push_back(v);
  for (auto [u, w] : g[v])
    comps(u);
}

void dfs(int v, int p) {
  if (d[v] > dmax[1]) dmax = {v, d[v]};
  for (auto [u, w] : g[v]) {
    if (u == p) continue;
    d[u] = d[v] + w;
    dfs(u, v);
  }
}

int diam(int v) {
  dmax = {v, 0}; dfs(v, -1);
  v = dmax[0]; d[v] = 0;
  dmax = {v, 0}; dfs(v, -1);
  return dmax[1];
}

int coda(int v) {
  // modo stupido O(n^2)
  int ans = 1e9;
  for (int u : cc[id[v]]) {
    fill(d.begin(), d.end(), 0);
    dfs(u, -1);
    ans = min(ans, *max_element(d.begin(), d.end()));
  }
  // cout << "coda[" << v << "] = " << ans << "\n";
  return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  g.resize(N);
  d.resize(N);
  id.resize(N, -1);
  for (int i = 0; i < M; ++i) {
    g[A[i]].push_back({B[i], T[i]});
    g[B[i]].push_back({A[i], T[i]});
  }
  for (int i = 0; i < N; ++i) {
    if (id[i] == -1) {
      cc.push_back(vector<int>(0));
      comps(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < int(cc.size()); ++i)
    ans = max(ans, diam(cc[i][0]));
  array<int, 3> o{};
  for (int i = 0; i < int(cc.size()); ++i) {
    o[2] = max(o[2], coda(cc[i][0]));
    if (o[1] < o[2]) swap(o[1], o[2]);
    if (o[0] < o[1]) swap(o[0], o[1]);
  }
  // cout << o[0] << " " << o[1] << " " << o[2] << "\n";
  if (int(cc.size()) == 1) return ans;
  ans = max(ans, o[0] + o[1] + L);
  if (int(cc.size()) == 2) return ans;
  ans = max(ans, o[1] + o[2] + 2*L);
  return ans;
}

#ifdef LORENZO
  int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, m, l;
    cin >> n >> m >> l;
    int a[100], b[100], t[100];
    for (int i = 0; i < m; ++i) cin >> a[i];
    for (int i = 0; i < m; ++i) cin >> b[i];
    for (int i = 0; i < m; ++i) cin >> t[i];
    cout << travelTime(n, m, l, a, b, t) << "\n";
  }
  #endif

Compilation message

dreaming.cpp: In function 'void comps(int)':
dreaming.cpp:17:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |   for (auto [u, w] : g[v])
      |             ^
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:23:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |   for (auto [u, w] : g[v]) {
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 11844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 11844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 8848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 6 ms 460 KB Output is correct
28 Correct 12 ms 576 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 7 ms 492 KB Output is correct
31 Correct 12 ms 460 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 7 ms 460 KB Output is correct
34 Correct 12 ms 576 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 184 ms 664 KB Output is correct
55 Correct 176 ms 588 KB Output is correct
56 Correct 12 ms 588 KB Output is correct
57 Correct 11 ms 588 KB Output is correct
58 Correct 82 ms 556 KB Output is correct
59 Correct 110 ms 460 KB Output is correct
60 Correct 10 ms 460 KB Output is correct
61 Correct 11 ms 616 KB Output is correct
62 Correct 69 ms 564 KB Output is correct
63 Correct 76 ms 568 KB Output is correct
64 Correct 10 ms 596 KB Output is correct
65 Correct 12 ms 588 KB Output is correct
66 Correct 140 ms 556 KB Output is correct
67 Correct 77 ms 460 KB Output is correct
68 Correct 11 ms 592 KB Output is correct
69 Correct 11 ms 460 KB Output is correct
70 Correct 10 ms 460 KB Output is correct
71 Correct 11 ms 572 KB Output is correct
72 Correct 119 ms 572 KB Output is correct
73 Correct 117 ms 460 KB Output is correct
74 Correct 12 ms 564 KB Output is correct
75 Correct 12 ms 460 KB Output is correct
76 Correct 83 ms 460 KB Output is correct
77 Correct 107 ms 460 KB Output is correct
78 Correct 11 ms 572 KB Output is correct
79 Correct 11 ms 460 KB Output is correct
80 Correct 10 ms 588 KB Output is correct
81 Correct 11 ms 588 KB Output is correct
82 Correct 12 ms 460 KB Output is correct
83 Correct 13 ms 572 KB Output is correct
84 Correct 19 ms 460 KB Output is correct
85 Correct 11 ms 588 KB Output is correct
86 Correct 48 ms 588 KB Output is correct
87 Correct 111 ms 460 KB Output is correct
88 Correct 11 ms 588 KB Output is correct
89 Correct 11 ms 588 KB Output is correct
90 Correct 11 ms 576 KB Output is correct
91 Correct 11 ms 580 KB Output is correct
92 Correct 30 ms 460 KB Output is correct
93 Correct 35 ms 472 KB Output is correct
94 Correct 43 ms 524 KB Output is correct
95 Correct 61 ms 512 KB Output is correct
96 Correct 49 ms 460 KB Output is correct
97 Correct 47 ms 460 KB Output is correct
98 Correct 56 ms 460 KB Output is correct
99 Correct 105 ms 460 KB Output is correct
100 Correct 73 ms 456 KB Output is correct
101 Correct 71 ms 460 KB Output is correct
102 Correct 1 ms 204 KB Output is correct
103 Correct 1 ms 204 KB Output is correct
104 Correct 1 ms 204 KB Output is correct
105 Correct 1 ms 204 KB Output is correct
106 Correct 0 ms 204 KB Output is correct
107 Correct 0 ms 204 KB Output is correct
108 Correct 0 ms 204 KB Output is correct
109 Correct 0 ms 204 KB Output is correct
110 Correct 0 ms 204 KB Output is correct
111 Correct 0 ms 204 KB Output is correct
112 Correct 1 ms 332 KB Output is correct
113 Correct 6 ms 380 KB Output is correct
114 Correct 9 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 11844 KB Time limit exceeded
2 Halted 0 ms 0 KB -