#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int a[200005], f[200005], d[200005];
vector<int> g[200005];
int 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 |
3 ms |
6744 KB |
Output is correct |
2 |
Correct |
59 ms |
16724 KB |
Output is correct |
3 |
Correct |
64 ms |
17212 KB |
Output is correct |
4 |
Correct |
65 ms |
17340 KB |
Output is correct |
5 |
Correct |
70 ms |
17880 KB |
Output is correct |
6 |
Correct |
66 ms |
17992 KB |
Output is correct |
7 |
Correct |
66 ms |
17848 KB |
Output is correct |
8 |
Incorrect |
2 ms |
6796 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6744 KB |
Output is correct |
2 |
Correct |
59 ms |
16724 KB |
Output is correct |
3 |
Correct |
64 ms |
17212 KB |
Output is correct |
4 |
Correct |
65 ms |
17340 KB |
Output is correct |
5 |
Correct |
70 ms |
17880 KB |
Output is correct |
6 |
Correct |
66 ms |
17992 KB |
Output is correct |
7 |
Correct |
66 ms |
17848 KB |
Output is correct |
8 |
Incorrect |
2 ms |
6796 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |