#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
int a[200005], f[200005], d[200005];
vector<int> g[200005];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[i] = d[i] = -1;
}
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
priority_queue<pair<int, int>> q;
q.push({0, 1});
while (!q.empty()) {
pair<int, int> p = q.top();
q.pop();
int x = -p.first, u = p.second;
for (int w : g[u]) {
if (f[w] != -1) continue;
f[w] = max(x + 1, a[w]);
q.push({-f[w], w});
}
}
q.push({0, n});
while (!q.empty()) {
pair<int, int> p = q.top();
q.pop();
int x = -p.first, u = p.second;
for (int w : g[u]) {
if (d[w] != -1) continue;
d[w] = max(x + 1, a[w]);
q.push({-d[w], w});
}
}
int res = 1e9;
for (int i = 1; i <= n; i++) {
res = min(res, max(f[i], d[i]) * 2);
}
for (int i = 1; i <= n; i++) {
for (int w : g[i]) {
if (f[i] == d[w]) res = min(res, f[i] * 2 + 1);
}
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
61 ms |
16044 KB |
Output is correct |
3 |
Correct |
61 ms |
15904 KB |
Output is correct |
4 |
Correct |
61 ms |
15952 KB |
Output is correct |
5 |
Correct |
62 ms |
16004 KB |
Output is correct |
6 |
Correct |
62 ms |
15952 KB |
Output is correct |
7 |
Correct |
62 ms |
15956 KB |
Output is correct |
8 |
Incorrect |
1 ms |
8796 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Incorrect |
1 ms |
8792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Incorrect |
1 ms |
8792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
61 ms |
16044 KB |
Output is correct |
3 |
Correct |
61 ms |
15904 KB |
Output is correct |
4 |
Correct |
61 ms |
15952 KB |
Output is correct |
5 |
Correct |
62 ms |
16004 KB |
Output is correct |
6 |
Correct |
62 ms |
15952 KB |
Output is correct |
7 |
Correct |
62 ms |
15956 KB |
Output is correct |
8 |
Incorrect |
1 ms |
8796 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |