Submission #1188926

#TimeUsernameProblemLanguageResultExecution timeMemory
1188926caterpillowAirplane (NOI23_airplane)C++20
63 / 100
1094 ms29520 KiB
#include <bits/stdc++.h>

#pragma GCC optimise("O3,unroll-loops");

using namespace std;

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int n, m; cin >> n >> m;
    if (n == 1) {
        cout << "0\n";
        return 0;
    }
    vector<int> h(n);
    for (int &x : h) cin >> x;
    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);
    }

    struct entry {
        int d, a, u;
        bool operator<(const entry &oth) const {
            return d > oth.d;
        }
    };

    auto funny_dijkstra = [&] (int s, vector<int> &dist, vector<int> &alt) {
        priority_queue<entry> pq;
        pq.push({h[s], h[s], s});
        while (pq.size()) {
            auto [d, a, u] = pq.top(); pq.pop();
            if (dist[u] < d) continue;
            dist[u] = d;
            alt[u] = a;
            for (int v : adj[u]) pq.push({max(d + 1, h[v]), max(alt[u], h[v]), v});
        }
    };

    vector<int> dist0(n, 1e9), dist1(n, 1e9), alt0(n), alt1(n);
    funny_dijkstra(0, dist0, alt0);
    funny_dijkstra(n - 1, dist1, alt1);
    int ans = 1e9;
    for (int i = 0; i < n; i++) {
        if (alt0[i] == alt1[i])
            ans = min(ans, dist0[i] + dist1[i]);
    }
    cout << ans << '\n';
}

Compilation message (stderr)

Main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...