#include <bits/stdc++.h>
using namespace std;
#define db(...) " [" << #__VA_ARGS__ << " : " << (__VA_ARGS__) << "] "
#define N 200005
int n, m;
int a[N];
vector<int> g[N];
// nhan xet: bay len den 1 diem mid sau do di xuong
int up[N]; // bay len
int down[N]; // bay xuong
template<class A, class B>
bool mini(A &a, const B &b) {
return a > b ? (a = b), true : false;
}
void dijkstra(int src, int d[]) {
fill(d + 1, d + n + 1, 2e8);
d[src] = 0;
using T = pair<int, int>;
priority_queue<T, vector<T>, greater<T>> pq;
pq.emplace(0, src);
while (pq.size()) {
auto [c, u] = pq.top();
pq.pop();
if (c != d[u]) {
continue;
}
for (int v : g[u]) {
if (mini(d[v], max(d[u], a[v]))) {
pq.emplace(d[v], v);
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
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;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
dijkstra(1, up);
dijkstra(n, down);
int res = 1e9;
for (int i = 1; i <= n; ++i) {
res = min(res, 2 * max(up[i], down[i]));
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
55 ms |
16852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
55 ms |
16852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |