답안 #891925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891925 2023-12-24T12:39:04 Z peterandvoi Airplane (NOI23_airplane) C++17
100 / 100
252 ms 24132 KB
#include <bits/stdc++.h>

using namespace std;

#define db(...) " [" << #__VA_ARGS__ << " : " << (__VA_ARGS__) << "] "

#define N   200005

int n, m;
int a[N];
vector<int> g[N];
// nhan xet: bay len den 1 diem mid sau do di xuong
int up[N]; // bay len
int down[N]; // bay xuong

template<class A, class B>
bool mini(A &a, const B &b) {
  return a > b ? (a = b), true : false;
}

void dijkstra(int src, int d[]) {
  fill(d + 1, d + n + 1, 2e8);
  d[src] = 0;
  using T = pair<int, int>;
  priority_queue<T, vector<T>, greater<T>> pq;
  pq.emplace(0, src);
  while (pq.size()) {
    auto [c, u] = pq.top();
    pq.pop();
    if (c != d[u]) {
      continue;
    }
    for (int v : g[u]) {
      if (mini(d[v], max(d[u] + 1, a[v]))) {
        pq.emplace(d[v], v);
      }
    }
  }
}
  
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  dijkstra(1, up);
  dijkstra(n, down);
  int res = 1e9;
  for (int i = 1; i <= n; ++i) {
    res = min(res, 2 * max(up[i], down[i]));
  }
  // giao nhau tai (u, v)
  for (int u = 1; u <= n; ++u) {
    for (int v : g[u]) {
      res = min(res, 2 * max(up[u], down[v]) + 1);
    }
  }
  cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 57 ms 13652 KB Output is correct
3 Correct 58 ms 17232 KB Output is correct
4 Correct 61 ms 17484 KB Output is correct
5 Correct 60 ms 18000 KB Output is correct
6 Correct 62 ms 17832 KB Output is correct
7 Correct 62 ms 17916 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6636 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6632 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6632 KB Output is correct
14 Correct 2 ms 6708 KB Output is correct
15 Correct 3 ms 6744 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6636 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6632 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6632 KB Output is correct
14 Correct 2 ms 6708 KB Output is correct
15 Correct 3 ms 6744 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 2 ms 6656 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6716 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6576 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 3 ms 6748 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 57 ms 13652 KB Output is correct
3 Correct 58 ms 17232 KB Output is correct
4 Correct 61 ms 17484 KB Output is correct
5 Correct 60 ms 18000 KB Output is correct
6 Correct 62 ms 17832 KB Output is correct
7 Correct 62 ms 17916 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6488 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6636 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6632 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6632 KB Output is correct
22 Correct 2 ms 6708 KB Output is correct
23 Correct 3 ms 6744 KB Output is correct
24 Correct 3 ms 6748 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 2 ms 6656 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6716 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6488 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6576 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 3 ms 6748 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 3 ms 6748 KB Output is correct
39 Correct 133 ms 18004 KB Output is correct
40 Correct 112 ms 17264 KB Output is correct
41 Correct 115 ms 17092 KB Output is correct
42 Correct 81 ms 17224 KB Output is correct
43 Correct 86 ms 17104 KB Output is correct
44 Correct 88 ms 17260 KB Output is correct
45 Correct 83 ms 16976 KB Output is correct
46 Correct 104 ms 17236 KB Output is correct
47 Correct 106 ms 17212 KB Output is correct
48 Correct 87 ms 16980 KB Output is correct
49 Correct 127 ms 17932 KB Output is correct
50 Correct 110 ms 17744 KB Output is correct
51 Correct 104 ms 17744 KB Output is correct
52 Correct 162 ms 20736 KB Output is correct
53 Correct 143 ms 19504 KB Output is correct
54 Correct 145 ms 19720 KB Output is correct
55 Correct 186 ms 19704 KB Output is correct
56 Correct 212 ms 22856 KB Output is correct
57 Correct 204 ms 23332 KB Output is correct
58 Correct 222 ms 24116 KB Output is correct
59 Correct 233 ms 24132 KB Output is correct
60 Correct 203 ms 24048 KB Output is correct
61 Correct 229 ms 24012 KB Output is correct
62 Correct 181 ms 22868 KB Output is correct
63 Correct 214 ms 22872 KB Output is correct
64 Correct 232 ms 23284 KB Output is correct
65 Correct 187 ms 23044 KB Output is correct
66 Correct 252 ms 23116 KB Output is correct
67 Correct 218 ms 23572 KB Output is correct