# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1102372 | 2024-10-18T03:20:10 Z | tuannm | Airplane (NOI23_airplane) | C++17 | 48 ms | 15092 KB |
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 2e5 + 1; const string NAME = ""; int n, m, a[N]; long long d[2][N]; vector<int> adj[N]; void inp(){ cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= m; ++i){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } void solve(){ priority_queue<pair<long long, int>> pq; for(int i = 1; i <= n; ++i) d[0][i] = d[1][i] = 1e16; d[0][1] = d[1][n] = 0; pq.push({0, 1}); while(!pq.empty()){ auto [dis, u] = pq.top(); pq.pop(); dis = -dis; if(dis != d[0][u]) continue; for(int v : adj[u]){ if(d[0][v] > max(d[0][u] + 1, 1LL * a[v])){ d[0][v] = max(d[0][u] + 1, 1LL * a[v]); pq.push({-d[0][v], v}); } } } pq.push({0, n}); while(!pq.empty()){ auto [dis, u] = pq.top(); pq.pop(); dis = -dis; if(dis != d[1][u]) continue; for(int v : adj[u]){ if(d[1][v] > max(d[1][u] + 1, 1LL * a[v])){ d[1][v] = max(d[1][u] + 1, 1LL * a[v]); pq.push({-d[1][v], v}); } } } long long ans = 1e16; for(int i = 2; i < n; ++i) ans = min(ans, d[0][i] + d[1][i]); cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Incorrect | 48 ms | 15092 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Correct | 2 ms | 8784 KB | Output is correct |
3 | Incorrect | 2 ms | 8784 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Correct | 2 ms | 8784 KB | Output is correct |
3 | Incorrect | 2 ms | 8784 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Incorrect | 48 ms | 15092 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |