답안 #1102345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102345 2024-10-18T02:58:17 Z thangdz2k7 Airplane (NOI23_airplane) C++17
100 / 100
283 ms 17496 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

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

int n, a[N];
vector <int> adj[N];

void dijkstra(int src, int d[]){
    fill(d + 1, d + n + 1, mod);
    using T = pair <int, int>;
    priority_queue <T, vector <T>, greater <T>> qu;
    d[src] = 0; qu.emplace(0, src);
    while (qu.size()){
        auto [du, u] = qu.top(); qu.pop();
        if (d[u] != du) continue;
        for (int v : adj[u]){
            if (minl(d[v], max(d[u] + 1, a[v]))){
                qu.emplace(d[v], v);
            }
        }
    }
}

int m, up[N], down[N];

void solve(){
    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;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dijkstra(1, up);
    dijkstra(n, down);
    int res = mod;
    for (int i = 1; i <= n; ++ i) {
        res = min(res, max(up[i], down[i]) * 2);
        for (int j : adj[i]) res = min(res, max(up[i], down[j]) * 2 + 1);
    }

    cout << res;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 52 ms 13640 KB Output is correct
3 Correct 52 ms 13648 KB Output is correct
4 Correct 72 ms 13640 KB Output is correct
5 Correct 53 ms 13600 KB Output is correct
6 Correct 55 ms 13712 KB Output is correct
7 Correct 62 ms 13732 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6648 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6480 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 4 ms 6900 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6648 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6480 KB Output is correct
15 Correct 3 ms 6736 KB Output is correct
16 Correct 4 ms 6900 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 2 ms 6480 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 2 ms 6688 KB Output is correct
21 Correct 3 ms 6480 KB Output is correct
22 Correct 3 ms 6700 KB Output is correct
23 Correct 3 ms 6480 KB Output is correct
24 Correct 2 ms 6656 KB Output is correct
25 Correct 2 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 3 ms 6480 KB Output is correct
28 Correct 4 ms 6736 KB Output is correct
29 Correct 3 ms 6736 KB Output is correct
30 Correct 4 ms 6736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 52 ms 13640 KB Output is correct
3 Correct 52 ms 13648 KB Output is correct
4 Correct 72 ms 13640 KB Output is correct
5 Correct 53 ms 13600 KB Output is correct
6 Correct 55 ms 13712 KB Output is correct
7 Correct 62 ms 13732 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 2 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 3 ms 6480 KB Output is correct
19 Correct 3 ms 6648 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 2 ms 6480 KB Output is correct
22 Correct 3 ms 6480 KB Output is correct
23 Correct 3 ms 6736 KB Output is correct
24 Correct 4 ms 6900 KB Output is correct
25 Correct 3 ms 6736 KB Output is correct
26 Correct 2 ms 6480 KB Output is correct
27 Correct 2 ms 6480 KB Output is correct
28 Correct 2 ms 6688 KB Output is correct
29 Correct 3 ms 6480 KB Output is correct
30 Correct 3 ms 6700 KB Output is correct
31 Correct 3 ms 6480 KB Output is correct
32 Correct 2 ms 6656 KB Output is correct
33 Correct 2 ms 6480 KB Output is correct
34 Correct 3 ms 6480 KB Output is correct
35 Correct 3 ms 6480 KB Output is correct
36 Correct 4 ms 6736 KB Output is correct
37 Correct 3 ms 6736 KB Output is correct
38 Correct 4 ms 6736 KB Output is correct
39 Correct 96 ms 13640 KB Output is correct
40 Correct 149 ms 13640 KB Output is correct
41 Correct 75 ms 13668 KB Output is correct
42 Correct 73 ms 13628 KB Output is correct
43 Correct 79 ms 13640 KB Output is correct
44 Correct 92 ms 13640 KB Output is correct
45 Correct 85 ms 13648 KB Output is correct
46 Correct 75 ms 13640 KB Output is correct
47 Correct 89 ms 13600 KB Output is correct
48 Correct 89 ms 13660 KB Output is correct
49 Correct 115 ms 13756 KB Output is correct
50 Correct 118 ms 13640 KB Output is correct
51 Correct 88 ms 13640 KB Output is correct
52 Correct 158 ms 15424 KB Output is correct
53 Correct 176 ms 15308 KB Output is correct
54 Correct 165 ms 15264 KB Output is correct
55 Correct 192 ms 15340 KB Output is correct
56 Correct 207 ms 17472 KB Output is correct
57 Correct 243 ms 17392 KB Output is correct
58 Correct 253 ms 17464 KB Output is correct
59 Correct 238 ms 17496 KB Output is correct
60 Correct 208 ms 17460 KB Output is correct
61 Correct 218 ms 17468 KB Output is correct
62 Correct 206 ms 17484 KB Output is correct
63 Correct 177 ms 17448 KB Output is correct
64 Correct 240 ms 17484 KB Output is correct
65 Correct 202 ms 17484 KB Output is correct
66 Correct 283 ms 17492 KB Output is correct
67 Correct 241 ms 17464 KB Output is correct