답안 #757760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757760 2023-06-13T17:49:38 Z taher 꿈 (IOI13_dreaming) C++17
59 / 100
1000 ms 9568 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

const int maxN = (int) 1e5 + 1;
vector<pair<int,int>> adj[maxN];
int cnt = 0, n, m, l,sz = 0, ans = 0;
bool vis[maxN];
int parent[maxN];
pair<int, int> p[maxN];

void init() {
  memset(parent, -1, sizeof(parent));
}

pair<int, int> bfs(int node) {
  sz = 0;
  bool seen[n];
  int depth[n];
  memset(seen, 0, sizeof(seen));
  memset(depth, 0, sizeof(depth));
  int best_node = node, best_dist = 0;
  depth[node] = 0;
  seen[node] = true; vis[node] = true;
  queue<int> qs;
  qs.emplace(node);
  while(!qs.empty()) {
    auto f = qs.front();
    sz++;
    if (depth[f] > best_dist) {
      best_dist = depth[f];
      best_node = f;
    }
    qs.pop();
    for (auto x : adj[f]) {
      if (seen[x.first]) continue;
      vis[x.first] = true;
      qs.emplace(x.first);
      parent[x.first] = f;
      depth[x.first] = x.second + depth[f];
      seen[x.first] = true;
    }
  }
  return make_pair(best_node, best_dist);
}

int Get_total(int node) {
  auto val = bfs(node);
  auto f = bfs(val.first);
  return f.second;
}

void Do(int node) {
  auto val = bfs(node);
  if (sz == 1) {
    p[cnt++] = make_pair(0, node);
    return ;
  }
  auto Tke = bfs(val.first);
  parent[val.first] = -1;
  int cur = Tke.first;
  vector<int> path, len;
  while(cur != -1) {
    int nxt = parent[cur];
    path.emplace_back(cur);
    if (nxt == -1) break;
    auto q = lower_bound(adj[cur].begin(), adj[cur].end(), make_pair(nxt, 0));
    len.emplace_back((*q).second);
    cur = parent[cur];    
  }
  int Max = (int)1e9, best_node = -1, s = 0;
  for (int i = 0; i < (int)path.size(); i++) {
    if (i > 0) s += len[i - 1];
    int now_max = max(s, Tke.second - s);
    if (now_max < Max) {
      Max = now_max;
      best_node = path[i];
    }
  }
  ans = max(ans, Tke.second);
  assert(best_node != -1);
  p[cnt++] = make_pair(Max, best_node);
  return ;
}

void make() {
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    Do(i);
    vis[i] = true;
  }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  n = N;
  m = M;
  l = L;
  init();

  for (int i = 0; i < m; i++) {
    adj[A[i]].emplace_back(B[i], T[i]);
    adj[B[i]].emplace_back(A[i], T[i]);
  }

  for (int i = 0; i < n; i++) {
    sort(adj[i].begin(),adj[i].end());
  }

  make();

  sort(p, p + n);
  if (cnt >= 2) {
    ans = max(ans, p[n - 1].first + p[n - 2].first + l);
  }
  if (cnt >= 3) {
    ans = max(ans, p[n - 2].first + p[n - 3].first + 2 * l);
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 8544 KB Output is correct
2 Correct 54 ms 8468 KB Output is correct
3 Correct 34 ms 6572 KB Output is correct
4 Correct 8 ms 3900 KB Output is correct
5 Correct 7 ms 3668 KB Output is correct
6 Correct 16 ms 4332 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 26 ms 5388 KB Output is correct
9 Correct 30 ms 6044 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 50 ms 7332 KB Output is correct
12 Correct 54 ms 7836 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 3 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 3 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 3 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 2 ms 3036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 8544 KB Output is correct
2 Correct 54 ms 8468 KB Output is correct
3 Correct 34 ms 6572 KB Output is correct
4 Correct 8 ms 3900 KB Output is correct
5 Correct 7 ms 3668 KB Output is correct
6 Correct 16 ms 4332 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 26 ms 5388 KB Output is correct
9 Correct 30 ms 6044 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 50 ms 7332 KB Output is correct
12 Correct 54 ms 7836 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 3 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3028 KB Output is correct
31 Correct 3 ms 3028 KB Output is correct
32 Correct 3 ms 3028 KB Output is correct
33 Correct 3 ms 3028 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 3 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3036 KB Output is correct
39 Correct 52 ms 8416 KB Output is correct
40 Correct 51 ms 8420 KB Output is correct
41 Correct 33 ms 6556 KB Output is correct
42 Correct 10 ms 3856 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 3 ms 3028 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 2 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 2 ms 3028 KB Output is correct
50 Correct 2 ms 3028 KB Output is correct
51 Correct 2 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 2 ms 3028 KB Output is correct
57 Correct 86 ms 9568 KB Output is correct
58 Correct 76 ms 9568 KB Output is correct
59 Correct 66 ms 9364 KB Output is correct
60 Correct 65 ms 9408 KB Output is correct
61 Correct 79 ms 9312 KB Output is correct
62 Correct 80 ms 9284 KB Output is correct
63 Correct 97 ms 9200 KB Output is correct
64 Correct 77 ms 9164 KB Output is correct
65 Correct 74 ms 9288 KB Output is correct
66 Correct 80 ms 9416 KB Output is correct
67 Correct 86 ms 9416 KB Output is correct
68 Correct 76 ms 9380 KB Output is correct
69 Correct 83 ms 9412 KB Output is correct
70 Correct 67 ms 9292 KB Output is correct
71 Correct 2 ms 3028 KB Output is correct
72 Correct 4 ms 3156 KB Output is correct
73 Correct 5 ms 3156 KB Output is correct
74 Correct 4 ms 3156 KB Output is correct
75 Correct 4 ms 3156 KB Output is correct
76 Correct 3 ms 3156 KB Output is correct
77 Correct 4 ms 3156 KB Output is correct
78 Correct 4 ms 3156 KB Output is correct
79 Correct 3 ms 3156 KB Output is correct
80 Correct 73 ms 9320 KB Output is correct
81 Correct 90 ms 9380 KB Output is correct
82 Correct 88 ms 9360 KB Output is correct
83 Correct 67 ms 9400 KB Output is correct
84 Correct 3 ms 3156 KB Output is correct
85 Correct 3 ms 3156 KB Output is correct
86 Correct 3 ms 3156 KB Output is correct
87 Correct 3 ms 3156 KB Output is correct
88 Correct 3 ms 3156 KB Output is correct
89 Correct 4 ms 3204 KB Output is correct
90 Correct 4 ms 3156 KB Output is correct
91 Correct 4 ms 3224 KB Output is correct
92 Correct 4 ms 3156 KB Output is correct
93 Correct 4 ms 3156 KB Output is correct
94 Correct 2 ms 3028 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 2 ms 3028 KB Output is correct
97 Correct 2 ms 3028 KB Output is correct
98 Correct 3 ms 3028 KB Output is correct
99 Correct 2 ms 3028 KB Output is correct
100 Correct 2 ms 3028 KB Output is correct
101 Correct 2 ms 3028 KB Output is correct
102 Correct 2 ms 3028 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 7 ms 3704 KB Output is correct
105 Correct 14 ms 4292 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 26 ms 5448 KB Output is correct
108 Correct 32 ms 6112 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 49 ms 7328 KB Output is correct
111 Correct 54 ms 7944 KB Output is correct
112 Correct 2 ms 3028 KB Output is correct
113 Correct 85 ms 8952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 6312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 3 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 3 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 3 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 2 ms 3036 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 3 ms 3156 KB Output is correct
28 Correct 3 ms 3156 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 3 ms 3156 KB Output is correct
31 Correct 6 ms 3156 KB Output is correct
32 Correct 3 ms 3028 KB Output is correct
33 Correct 5 ms 3156 KB Output is correct
34 Correct 4 ms 3156 KB Output is correct
35 Correct 2 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3028 KB Output is correct
39 Correct 2 ms 3028 KB Output is correct
40 Correct 2 ms 3028 KB Output is correct
41 Correct 2 ms 3028 KB Output is correct
42 Correct 2 ms 3028 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 2 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 2 ms 3028 KB Output is correct
50 Correct 2 ms 3028 KB Output is correct
51 Correct 2 ms 3028 KB Output is correct
52 Correct 2 ms 3004 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
54 Correct 3 ms 3284 KB Output is correct
55 Correct 3 ms 3156 KB Output is correct
56 Correct 3 ms 3156 KB Output is correct
57 Correct 5 ms 3156 KB Output is correct
58 Correct 3 ms 3156 KB Output is correct
59 Correct 3 ms 3156 KB Output is correct
60 Correct 4 ms 3156 KB Output is correct
61 Correct 4 ms 3060 KB Output is correct
62 Correct 4 ms 3156 KB Output is correct
63 Correct 4 ms 3156 KB Output is correct
64 Correct 3 ms 3028 KB Output is correct
65 Correct 4 ms 3156 KB Output is correct
66 Correct 4 ms 3156 KB Output is correct
67 Correct 3 ms 3156 KB Output is correct
68 Correct 4 ms 3156 KB Output is correct
69 Correct 4 ms 3156 KB Output is correct
70 Correct 4 ms 3156 KB Output is correct
71 Correct 3 ms 3156 KB Output is correct
72 Correct 4 ms 3156 KB Output is correct
73 Correct 3 ms 3212 KB Output is correct
74 Correct 4 ms 3156 KB Output is correct
75 Correct 5 ms 3156 KB Output is correct
76 Correct 5 ms 3156 KB Output is correct
77 Correct 5 ms 3156 KB Output is correct
78 Correct 4 ms 3156 KB Output is correct
79 Correct 5 ms 3156 KB Output is correct
80 Correct 4 ms 3028 KB Output is correct
81 Correct 5 ms 3028 KB Output is correct
82 Correct 4 ms 3156 KB Output is correct
83 Correct 4 ms 3156 KB Output is correct
84 Correct 3 ms 3168 KB Output is correct
85 Correct 3 ms 3028 KB Output is correct
86 Correct 3 ms 3212 KB Output is correct
87 Correct 3 ms 3156 KB Output is correct
88 Correct 4 ms 3156 KB Output is correct
89 Correct 4 ms 3156 KB Output is correct
90 Correct 5 ms 3156 KB Output is correct
91 Correct 4 ms 3156 KB Output is correct
92 Correct 3 ms 3156 KB Output is correct
93 Correct 3 ms 3156 KB Output is correct
94 Correct 4 ms 3156 KB Output is correct
95 Correct 3 ms 3156 KB Output is correct
96 Correct 3 ms 3156 KB Output is correct
97 Correct 3 ms 3232 KB Output is correct
98 Correct 3 ms 3156 KB Output is correct
99 Correct 4 ms 3156 KB Output is correct
100 Correct 3 ms 3156 KB Output is correct
101 Correct 3 ms 3156 KB Output is correct
102 Correct 2 ms 3028 KB Output is correct
103 Correct 2 ms 3076 KB Output is correct
104 Correct 2 ms 3028 KB Output is correct
105 Correct 2 ms 3028 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 2 ms 3004 KB Output is correct
108 Correct 2 ms 3028 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 2 ms 3028 KB Output is correct
111 Correct 2 ms 3028 KB Output is correct
112 Correct 2 ms 3028 KB Output is correct
113 Correct 2 ms 3028 KB Output is correct
114 Correct 2 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 8544 KB Output is correct
2 Correct 54 ms 8468 KB Output is correct
3 Correct 34 ms 6572 KB Output is correct
4 Correct 8 ms 3900 KB Output is correct
5 Correct 7 ms 3668 KB Output is correct
6 Correct 16 ms 4332 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 26 ms 5388 KB Output is correct
9 Correct 30 ms 6044 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 50 ms 7332 KB Output is correct
12 Correct 54 ms 7836 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 3 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3028 KB Output is correct
31 Correct 3 ms 3028 KB Output is correct
32 Correct 3 ms 3028 KB Output is correct
33 Correct 3 ms 3028 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 3 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3036 KB Output is correct
39 Correct 52 ms 8416 KB Output is correct
40 Correct 51 ms 8420 KB Output is correct
41 Correct 33 ms 6556 KB Output is correct
42 Correct 10 ms 3856 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 3 ms 3028 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 2 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 2 ms 3028 KB Output is correct
50 Correct 2 ms 3028 KB Output is correct
51 Correct 2 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 2 ms 3028 KB Output is correct
57 Correct 86 ms 9568 KB Output is correct
58 Correct 76 ms 9568 KB Output is correct
59 Correct 66 ms 9364 KB Output is correct
60 Correct 65 ms 9408 KB Output is correct
61 Correct 79 ms 9312 KB Output is correct
62 Correct 80 ms 9284 KB Output is correct
63 Correct 97 ms 9200 KB Output is correct
64 Correct 77 ms 9164 KB Output is correct
65 Correct 74 ms 9288 KB Output is correct
66 Correct 80 ms 9416 KB Output is correct
67 Correct 86 ms 9416 KB Output is correct
68 Correct 76 ms 9380 KB Output is correct
69 Correct 83 ms 9412 KB Output is correct
70 Correct 67 ms 9292 KB Output is correct
71 Correct 2 ms 3028 KB Output is correct
72 Correct 4 ms 3156 KB Output is correct
73 Correct 5 ms 3156 KB Output is correct
74 Correct 4 ms 3156 KB Output is correct
75 Correct 4 ms 3156 KB Output is correct
76 Correct 3 ms 3156 KB Output is correct
77 Correct 4 ms 3156 KB Output is correct
78 Correct 4 ms 3156 KB Output is correct
79 Correct 3 ms 3156 KB Output is correct
80 Correct 73 ms 9320 KB Output is correct
81 Correct 90 ms 9380 KB Output is correct
82 Correct 88 ms 9360 KB Output is correct
83 Correct 67 ms 9400 KB Output is correct
84 Correct 3 ms 3156 KB Output is correct
85 Correct 3 ms 3156 KB Output is correct
86 Correct 3 ms 3156 KB Output is correct
87 Correct 3 ms 3156 KB Output is correct
88 Correct 3 ms 3156 KB Output is correct
89 Correct 4 ms 3204 KB Output is correct
90 Correct 4 ms 3156 KB Output is correct
91 Correct 4 ms 3224 KB Output is correct
92 Correct 4 ms 3156 KB Output is correct
93 Correct 4 ms 3156 KB Output is correct
94 Correct 2 ms 3028 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 2 ms 3028 KB Output is correct
97 Correct 2 ms 3028 KB Output is correct
98 Correct 3 ms 3028 KB Output is correct
99 Correct 2 ms 3028 KB Output is correct
100 Correct 2 ms 3028 KB Output is correct
101 Correct 2 ms 3028 KB Output is correct
102 Correct 2 ms 3028 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 7 ms 3704 KB Output is correct
105 Correct 14 ms 4292 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 26 ms 5448 KB Output is correct
108 Correct 32 ms 6112 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 49 ms 7328 KB Output is correct
111 Correct 54 ms 7944 KB Output is correct
112 Correct 2 ms 3028 KB Output is correct
113 Correct 85 ms 8952 KB Output is correct
114 Execution timed out 1079 ms 6312 KB Time limit exceeded
115 Halted 0 ms 0 KB -