Submission #914212

# Submission time Handle Problem Language Result Execution time Memory
914212 2024-01-21T11:14:34 Z vjudge1 Airplane (NOI23_airplane) C++17
0 / 100
69 ms 13788 KB
#include<bits/stdc++.h>
 
using namespace std;

vector<int> Dijkstra(int start, vector<vector<int>>& adj, vector<int>& a){
    int n = (int)adj.size();
    vector<int> dist(n, 2e9);
    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 = 2e9;
    for(int i = 0; i < n; i++){
        int cost = max(dist1[i], distN[i]) * 2;
        if(abs(dist1[i] - distN[i]) == 1 && min(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 1 ms 348 KB Output is correct
2 Correct 58 ms 13632 KB Output is correct
3 Correct 69 ms 13776 KB Output is correct
4 Correct 59 ms 13652 KB Output is correct
5 Correct 62 ms 13748 KB Output is correct
6 Correct 61 ms 13640 KB Output is correct
7 Correct 61 ms 13788 KB Output is correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 58 ms 13632 KB Output is correct
3 Correct 69 ms 13776 KB Output is correct
4 Correct 59 ms 13652 KB Output is correct
5 Correct 62 ms 13748 KB Output is correct
6 Correct 61 ms 13640 KB Output is correct
7 Correct 61 ms 13788 KB Output is correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Halted 0 ms 0 KB -