Submission #914216

# Submission time Handle Problem Language Result Execution time Memory
914216 2024-01-21T11:20:01 Z vjudge1 Airplane (NOI23_airplane) C++17
100 / 100
377 ms 26560 KB
#include<bits/stdc++.h>
 
using namespace std;

#define int long long

vector<int> Dijkstra(int start, vector<vector<int>>& adj, vector<int>& a){
    int n = (int)adj.size();
    vector<int> dist(n, 1e18);
    vector<bool> vis(n, false);
    dist[start] = 0;
    priority_queue<pair<int, int>> q; q.push({0, start});
    while(!q.empty()){
        int x = q.top().second; q.pop();
        if(vis[x]) continue;
        vis[x] = true;
        for(int& node : adj[x]){
            if(dist[node] > max(a[node], dist[x] + 1)){
                dist[node] = max(a[node], dist[x] + 1);
                q.push({-dist[node], node});
            }
        }
    }
    return dist;
}

void solve(){
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(auto &i : a) cin >> i;
    vector<vector<int>> adj(n);
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v; u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    vector<int> dist1 = Dijkstra(0, adj, a);
    vector<int> distN = Dijkstra(n-1, adj, a);
    int ans = 1e18;
    for(int i = 0; i < n; i++){
        int cost = max(dist1[i], distN[i]) * 2;
        if(abs(dist1[i] - distN[i]) == 1) cost--;
        ans = min(ans, cost);
    }
    cout << ans << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    // int tt; cin >> tt;
    int tt = 1;
    while(tt--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 63 ms 15956 KB Output is correct
3 Correct 71 ms 15932 KB Output is correct
4 Correct 60 ms 15956 KB Output is correct
5 Correct 97 ms 16104 KB Output is correct
6 Correct 65 ms 15956 KB Output is correct
7 Correct 85 ms 15952 KB Output is correct
8 Correct 0 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 720 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 63 ms 15956 KB Output is correct
3 Correct 71 ms 15932 KB Output is correct
4 Correct 60 ms 15956 KB Output is correct
5 Correct 97 ms 16104 KB Output is correct
6 Correct 65 ms 15956 KB Output is correct
7 Correct 85 ms 15952 KB Output is correct
8 Correct 0 ms 416 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 424 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 720 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 600 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 151 ms 17176 KB Output is correct
40 Correct 107 ms 16980 KB Output is correct
41 Correct 101 ms 17144 KB Output is correct
42 Correct 122 ms 17280 KB Output is correct
43 Correct 153 ms 16976 KB Output is correct
44 Correct 118 ms 16976 KB Output is correct
45 Correct 145 ms 17264 KB Output is correct
46 Correct 168 ms 17032 KB Output is correct
47 Correct 112 ms 17188 KB Output is correct
48 Correct 115 ms 17112 KB Output is correct
49 Correct 187 ms 17468 KB Output is correct
50 Correct 191 ms 16980 KB Output is correct
51 Correct 148 ms 16976 KB Output is correct
52 Correct 326 ms 21796 KB Output is correct
53 Correct 200 ms 21612 KB Output is correct
54 Correct 209 ms 21632 KB Output is correct
55 Correct 294 ms 21948 KB Output is correct
56 Correct 329 ms 25608 KB Output is correct
57 Correct 309 ms 25904 KB Output is correct
58 Correct 296 ms 25540 KB Output is correct
59 Correct 349 ms 25500 KB Output is correct
60 Correct 294 ms 25716 KB Output is correct
61 Correct 311 ms 26560 KB Output is correct
62 Correct 317 ms 25744 KB Output is correct
63 Correct 275 ms 25568 KB Output is correct
64 Correct 295 ms 25552 KB Output is correct
65 Correct 332 ms 25552 KB Output is correct
66 Correct 338 ms 25552 KB Output is correct
67 Correct 377 ms 25728 KB Output is correct